I am making a game for my ITS Class. I have made an Animation which is meant to be a “Moving Wall” in which if the “Player” collides with it, the “Player” re-spawns at the start of the Map.
The "Player collides and re-spawns but when it re-spawns the “Player” keeps moving forward and i can’t stop it.
I have tried everything i know (Which is not much as i am relatively new to Unity :P) and searched the Forums but have not found an answer.
My thanks to anyone who can help me with my problem =).
*Edit*
Player Controller
var speed = 500.0;
var rotateSpeed = 1.0;
var bulletPrefab:Transform;
var bulletSpeed = 20000.0;
var bullet1Prefab:Transform;
var bullet1Speed = 20000.0;
private var dead = false;
//function OnControllerColliderHit(hit : ControllerColliderHit)
function OnTriggerEnter (hit:Collider)
{
if(hit.gameObject.tag == "Fallout")
{
dead = true;
Application.LoadLevel (1);
}
if(hit.gameObject.tag == "EnemyBullet")
{
Destroy (hit.gameObject);
dead = true;
//subtract life here
HealthControl.LIVES -= 1;
}
if(hit.gameObject.tag == "AniWall")
{
dead = true;
//subtract life here
HealthControl.LIVES -= 1;
}
}
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
// Rotate around Y - Axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
// Move forward / backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Fire1"))
{
var bullet = Instantiate(bulletPrefab, GameObject.Find("SpawnPoint").transform.position, Quaternion.identity);
var bullet1 = Instantiate(bulletPrefab, GameObject.Find("SpawnPoint1").transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * bulletSpeed);
bullet1.rigidbody.AddForce(transform.forward * bullet1Speed);
}
}
function LateUpdate()
{
if(dead)
{
transform.position = Vector3(-991.336,46.12195,-775.5392);
gameObject.Find("Main Camera").transform.position = Vector3(10,4,-20);
dead = false;
}
}
@script RequireComponent(CharacterController)