Here's my script. Is there a way to start a new scene start as soon as the enemy hits the player?
var target : Transform;
var lookAtDistance = 20.0;
var attackRange = 15.0;
var moveSpeed = 20.0;
var damping = 6.0;
private var isItAttacking = false;
function Update ()
{
distance = Vector3.Distance(target.position, transform.position);
if(distance < lookAtDistance)
{
isItAttacking = false;
renderer.material.color = Color.white;
lookAt ();
}
if(distance > lookAtDistance)
{
renderer.material.color = Color.white;
}
if(distance < attackRange)
{
attack ();
}
if(isItAttacking)
{
renderer.material.color = Color.red;
}
}
function lookAt ()
{
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
function attack ()
{
isItAttacking = true;
renderer.material.color = Color.red;
transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);
}
Is there a way to make a new scene start as soon as the enemy hits the player?
↧