Left hand side of an assignment must be a variable, a property or an indexer
in this script that I copied from a tutorial theres a problem in the line GetComponent rigidbody2d = vector2.zero. The error is as the title says. I changed the line according to the comments since the line he used in the tutorial wasnt valid for unity 5. But this line doesnt work either and i dont know what to change.
{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.GetComponent<Renderer> ().enabled = false;
GetComponent<Rigidbody2D> () = Vector2.zero;
Debug.Log ("Player Respawn");
yield return new WaitForSeconds (respawnDelay);
player.transform.position = currentCheckpoint.transform.position;
player.enabled = true;
player.GetComponent<Renderer> ().enabled = true;
Instantiate (respawnParticle, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation); }}
Answer by Nomenokes · Aug 21, 2017 at 04:16 AM
GetComponent<Rigidbody2D>().velocity = Vector2.zero;
I think that's what your intention was.
That does fix the error but what the intention is for that line of code is that it should stop the player after he dies / stop the camera when the player dies. Now the problem is that 1. the camera still doesnt stop and 2. the player doesnt respawn
Ah. It looks like this script is attached to the camera. You will need to move the camera back to correct position as well (`transform.position=new Vector3(currentCheckpoint.transform.position.x,currentCheckpoint.transform.position.y+10,currentCheckpoint.transform.position.z`) or whatever your camera position should be.
I don't know why the player does not respawn. This code does not make the character "die" and "come back" but just moves them from current point to respawn point. Try the stuff above and get back to me if it still doesn't work.
The script is not attached to the camera. Its attached to the gameobject levelmanager which is why the script is called that. I think what that line is trying to do (correct me if im wrong, im quite new to coding) is set the velocity of the player to 0 and since the camera is a child of the player it should set the cameras velocity to 0 to (i think).
@Powerpuncher500 (forgot to notify you)
Your answer
Follow this Question
Related Questions
Angular Velocity to zero 0 Answers
Changing script variable from another script doesn't change it in the original script? 0 Answers
How do I keep enemies (rigidbodies) from pushing each other? 1 Answer
How to stop cube from sliding (rg2d.velocity) 1 Answer
Adding Rigidbody2d to gameobject removes it from game 0 Answers