15 January 2015

games mechanic notes - Scripting

#pragma strict

public var Sword : GameObject;
public var enemyhealth : int = 10;

function OnTriggerEnter (Sword : Collider)
{
if (Sword.tag == "Weapon")
{
enemyhealth --;
Sword.tag = "None";
}
}

function Update () 
{
if (enemyhealth == 0)
{
transform.position.y = -100;
}
}

This script deals with the interaction between the player and the enemy.

#pragma strict

public var Swing : boolean;
public var Sword :GameObject;

function Start()
{
Swing = false;
Sword.tag = "None";
}

function Update() 
{
if(Input.GetMouseButtonDown(0)&&Swing == false)
{
SwordSwing();
}
}

function SwordSwing()
{
Swing = true;
Sword.tag ="Weapon";
animation.Play("Stab", PlayMode.StopAll);
yield WaitForSeconds (5.5);
Sword.tag = "None";
Swing = false;
}

It works closely in tandem with this script, which deals with sword swings and activating the players weapon.

No comments:

Post a Comment