Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Recieving a nullpointerexception while following the Unity Instantiation tutorial

$
0
0
I am coding this in C#, and I ran into this issue while coding a simple script to shoot a ball from inside of my character. I have figured out it is coming from the AddForce function after casting as a Rigidbody, but can't figure out which value is null. using UnityEngine; using System.Collections; public class Shoot : MonoBehaviour { public Rigidbody bulletPrefab; public Transform playerCenter; void Update() { if(Input.GetButtonDown("Fire1")) { Rigidbody bulletSpawn = Instantiate(bulletPrefab, //The prefab spawned playerCenter.position, //Gets the position the prefab will go playerCenter.rotation) as Rigidbody; //Gets the rotation the prefab will go bulletSpawn.AddForce(playerCenter.forward * 5000); } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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