I have an enemy that works fine until I make it a prefab. There is an Enemy script with the player dragged into the inspector so I tried to use Find to avoid this for the prefab; however, now I get the error above since I Find the player GameObject yet I’m doing a Rigidbody to it later.
I’m using javascript.
Here’s my code
#pragma strict
var player : Rigidbody;
var bounceAmount = 5f;
var deathParticles : Transform;
//Enemies don't work since the player isn't found.
//The following is trying to remedy that for the "Enemy" script
function Awake() {
player = GameObject.Find("Player");
Debug.Log("Enemy script - was able to Find Player");
}
function Die () {
player.GetComponent.<Rigidbody>().velocity.y = bounceAmount;
Instantiate (deathParticles, transform.position, transform.rotation);
Destroy (gameObject);
}
I looked at other solutions and tried “as Rigidbody” but still got the same error. I tried to Find a Rigidbody instead but it wouldn’t let me do that.
TIA