Game Development Reference
In-Depth Information
var damage = 1;
var attackSpeed = 1.0;
var attackRotateSpeed = 20.0;
var idleTime = 1.6;
var punchPosition = new Vector3 (0.4, 0, 0.7);
var punchRadius = 1.1;
var idleSound : AudioClip;
var attackSound : AudioClip;
private var attackAngle = 10.0;
private var isAttacking = false;
private var lastPunchTime = 0.0;
var target : Transform;
private var characterController : CharacterController;
characterController = GetComponent(CharacterController);
The next section sets all of the zombie's actions to loop so that they play again once
they have reached their final frames. This function also tells the zombie object to use
any objects tagged as Player objects as targets if the developer does not define the target
transform variable:
function Start ()
{
if (!target)
target = GameObject.FindWithTag(“Player”).transform;
animation.wrapMode = WrapMode.Loop;
animation.Stop();
}
audio.clip = idleSound;
yield WaitForSeconds(Random.value);
while (true)
{
yield Idle();
yield Attack();
}
The next two sections make the zombie idle when the player is not around and rotate
toward the player at a set speed when it does find the player. Audio clips and animations
are called in the Idle function.
function Idle ()
{
animation.Play(“idle”);
if (idleSound)
{
if (audio.clip != idleSound)
{
audio.Stop();
audio.clip = idleSound;
Search WWH ::




Custom Search