Quantcast
Channel: Questions in topic: "unassiunassignedreferenceexception"
Viewing all articles
Browse latest Browse all 30

UnassignedReferenceException: The variable has not been assigned, even though it has. - c#

$
0
0
I have a script that controls shooting and it's assigned to a prefab. I hit play to see if it works and it says this when I shoot: UnassignedReferenceException: The variable player of BulletController has not been assigned. You probably need to assign the player variable of the BulletController script in the inspector. UnityEngine.GameObject.GetComponent[PlayerController] () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineGameObjectBindings.gen.cs:35) BulletController.Start () (at Assets/Scripts/BulletController.cs:22) However as you can see I've assigned my player variable: ![alt text][1] [1]: /storage/temp/53322-assigned-player.png I did click apply as well but nothing happened. I tried clicking on the cog icon and clicking reset but it still didn't work. using UnityEngine; using UnityEngine.UI; using System.Collections; public class BulletController : MonoBehaviour { PlayerController PlayerControllerScript; public float speed; public float coolDown = 5f; public float coolDownTimer; public Transform bullet; public GameObject player; //Rigidbody2D rb; void Start() { PlayerControllerScript = player.GetComponent (); } void Update() { Firing (); bulletActive (); } void Firing() { bullet.position += bullet.up * Time.deltaTime * speed; } public void OnTriggerEnter2D(Collider2D other) { if(other.CompareTag("Enemy")) { Destroy(other.gameObject); PlayerControllerScript.score += 10; PlayerControllerScript.ScoreText(); } Destroy (gameObject); } Thanks in advance.

Viewing all articles
Browse latest Browse all 30

Trending Articles



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