NullReferenceException: Object reference not set to an instance of an object
Cannon_Fire.Update () (at C:/Users/User/Dropbox/Pirategame/Assets/Scripts/Cannon_Fire.js:28)
private var initialVelocity: float; // Starting Speed
private var cannonMuzzle: GameObject; // The Muzzle From where it shoots from
private var cannonBall: Rigidbody; // Place holder for the creation of the projectile
private var interaction: String; //interaction type
function Update () {
initialVelocity = 200; // Setting speed
cannonMuzzle = GameObject.Find("Cannon/Bone001/Cannonbone/Projectiles"); //Will find the ammo
interaction = GameObject.Find("First Person Controller").GetComponent(Interactions).interaction; //Check interaction
if (Input.GetKeyDown("mouse 0") && interaction == "Cannon") {
cannonBall = Instantiate(cannonballPrefab, cannonMuzzle.transform.position, cannonMuzzle.transform.rotation); // Creates the projectile
cannonBall.velocity = transform.TransformDirection(Vector3.forward * initialVelocity); // Add a forward motion onto it.
cannonMuzzle.particleSystem.Play(); // Play fire animation
**GameObject.Find("Cannon").GetComponent(Animation).animation.Play("Take001") ;**
}
}
I’ve tried a few attempts, but nothing worked.