Hi,
I am incredibly new to programming and I am trying to respawn my gameobject once it collides with a deathpit and is then destroyed, below is the code I am trying to use;
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public float movementSpeed;
public KeyCode forwardKey;
public KeyCode leftKey;
public KeyCode rightKey;
public KeyCode backwardKey;
public GameObject respawnPreFab;
public GameObject respawn;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (respawn == null)
respawn = GameObject.FindWithTag ("character");
Instantiate(respawnPreFab, respawn.transform.position, respawn.transform.rotation)
as GameObject;
}
void FixedUpdate () {
checkKeysHeld ();
}
public void checkKeysHeld ()
{
if (Input.GetKey (forwardKey))
{
moveForward ();
}
if (Input.GetKey (leftKey))
{
moveLeft ();
}
if (Input.GetKey (rightKey))
{
moveRight ();
}
if (Input.GetKey (backwardKey))
{
moveBackward ();
}
}
public void moveForward ()
{
gameObject.rigidbody.AddForce (Vector3.forward * movementSpeed);
}
public void moveLeft ()
{
gameObject.rigidbody.AddForce (Vector3.left * movementSpeed);
}
public void moveRight ()
{
gameObject.rigidbody.AddForce (Vector3.right * movementSpeed);
}
public void moveBackward ()
{
gameObject.rigidbody.AddForce (Vector3.back * movementSpeed);
}
}