- Home /
there is no renderer attached to the "player" game object, but script is trying to access it.
I'm kinda new to unity and having some trouble, After finishing writing the code and saving it i tried playing the game which work, but when my player dies he won't disappear and re spawn only the console will keep on telling me "there is no 'rendered' attached to the 'player' game object, but a script is trying to access it." I don't know what to do? Any help?
using UnityEngine; using System.Collections;
public class LevelManager : MonoBehaviour {
public GameObject currentCheckpoint;
private PlayerController player;
public GameObject deathParticle;
public GameObject respawnParticle;
public float respawnDelay;
// Use this for initialization
void Start () {
player = FindObjectOfType<PlayerController>();
}
// Update is called once per frame
void Update () {
}
public void RespawnPlayer()
{
StartCoroutine("RespawnPlayerCo");
}
public IEnumerator RespawnPlayerCo()
{
Instantiate (deathParticle, player.transform.position, player.transform.rotation);
player.enabled = false;
player.renderer.enabled = false;
Debug.Log ("player Respawn");
yield return new WaitForSeconds(respawnDelay);
player.transform.position = currentCheckpoint.transform.position;
player.enabled = true;
player.renderer.enabled = true;
Instantiate(respawnParticle, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);
}
}
Your answer
Follow this Question
Related Questions
Trying to make a side scroller. I'm following a tutorial and getting this error. 1 Answer
How to add sign interaction? 1 Answer
Help with getting script of another player 0 Answers
Why my character moves left when i press right key ? Controls are upside down? 2 Answers
VR Player enters trigger won't work 0 Answers