When I try to run my game I get the following error:
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Here is my code but to tell the truth I don't know why the problem occurs or what exactly causes the problem.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DisparoMovimiento : MonoBehaviour {
public GameObject player;
private Transform playerTrans;
private Rigidbody2D DisparoRB;
public float DisparoSpeed;
public float bolitalife;
void Awake(){
DisparoRB = GetComponent<Rigidbody2D>();
player = GameObject.FindGameObjectWithTag("Player");
playerTrans = player.transform;
}
// Use this for initialization
void Start () {
if (playerTrans.localScale.x > 0){
DisparoRB.velocity = new Vector2(DisparoSpeed, DisparoRB.velocity.y);
transform.localScale = new Vector3(1, 1, 1);
}
else{
DisparoRB.velocity = new Vector2(-DisparoSpeed, DisparoRB.velocity.y);
transform.localScale = new Vector3(-1, 1, 1);
}
}
// Update is called once per frame
void Update(){
}
}
The problem is that your gameObject is not taking the reference well, either because you have modified it or because you have updated Unity, try to reference it again or create the gameobject again adding the same script and the reference. You may not see any change because the update is empty, try to put something in it