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

UnassignedReferenceException

$
0
0
I have a bomb explosion script where i press space to make a bomb explode. @Llama_w_2Ls yeah sure using System.Collections; using System.Collections.Generic; using UnityEngine; public class BombScript : MonoBehaviour { public float fieldofImpact; public float force; public LayerMask LayerToHit; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { Debug.Log("Test"); explode(); } } void explode() { Collider2D[] objects = Physics2D.OverlapCircleAll(transform.position, fieldofImpact, LayerToHit); foreach(Collider2D obj in objects) { Vector2 direction = obj.transform.position - transform.position; obj.GetComponent().AddForce(direction * force); } } private void OnDrawGizmosSelected() { Gizmos.color = Color.red; Gizmos.DrawWireSphere(transform.position, fieldofImpact); } } When i press space i get the "Test" message in console along with: UnassignedReferenceException: The variable explosion of ExplodeBomb has not been assigned. You probably need to assign the explosion variable of the ExplodeBomb script in the inspector. The script is assigned only to the bomb object. If i execute the explode function in void update with no condition before, it works, in the way that it continuously explodes, of course. Tried using both Unity 2019 & 2020.

Viewing all articles
Browse latest Browse all 2891

Latest Images

Trending Articles



Latest Images

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