Hi,
So im struggling, i have my camera script which follows the player, upon death i respawn, but this breaks the camera with this:
MissingReferenceException: The object of type ‘Transform’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object
I cannot figure it out or seem to find a suitable answer that doesnt cause more problems, so two days of googling and youtube is getting me nowhere.
heres my scripts:
PlayerRespawn
#pragma strict
var Player : GameObject;
var spawnPoint : Transform;
function OnTriggerEnter2D(other : Collider2D){
Destroy (other.gameObject);
var P : GameObject = Instantiate(Player, spawnPoint.position, Quaternion.identity);
var sf = Camera.main.GetComponent(SmoothFollow2D);
sf.target = P.transform;
}
and here is the camera script:
#pragma strict
var target : Transform;
var smoothTime = 0.3;
private var thisTransform : Transform;
private var velocity : Vector2;
function Start()
{
thisTransform = transform;
}
function Update()
{
thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x,
target.position.x, velocity.x, smoothTime);
thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y,
target.position.y, velocity.y, smoothTime);
}
any help would be greatly appreciated, thanks.