Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

NullReferenceException: game object not set to an instance of an object from Cannonball Vector3 Calculation Script

$
0
0
as of right now I'm not getting any errors on this script because I was annoyed looking at my 999+ errors so I clicked clear on play, but despite not having any errors come back it simply isn't working for me. I made this to calculate a vector perpendicular to the direction the boat is heading so that I could shoot a cannonball perpendicular to the ship. I do remember an error that pertained to this code was a null reference exception: object not set to an instance of an object on line 43. any help will be appreciated thank you. using System.Collections; using System.Collections.Generic; using UnityEngine; public class CBC : MonoBehaviour { public GameObject cannonball; public GameObject boat; private Vector3 myposition; private Vector3 nextPosition; private Vector3 ballPosition; private Vector3 heading; private Vector3 toBall; private Vector3 ShootVector; private Rigidbody rb3d; public float shootForce; // Use this for initialization void Start () { rb3d = cannonball.GetComponent (); cannonball.SetActive(false); boat.gameObject.transform.position = myposition; nextPosition = myposition + new Vector3 (5, 0, 0); } // Update is called once per frame void Update () { heading = nextPosition - myposition; toBall = ballPosition - myposition; ShootVector = Vector3.Cross (heading, toBall); if (Input.GetKeyDown (KeyCode.Space)) { cannonball.SetActive (true); rb3d.AddForce(ShootVector * shootForce); } } }

Viewing all articles
Browse latest Browse all 2891


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>