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

ArgumentNullException: Value cannot be null. Parameter name: collider

$
0
0
ive been trying to make a top down game and recently this error kept on appearing and im not sure how to fix it the full error message is this : ArgumentNullException: Value cannot be null. Parameter name: collider UnityEngine.PhysicsScene2D.OverlapColliderArray_Internal (UnityEngine.Collider2D collider, UnityEngine.ContactFilter2D contactFilter, UnityEngine.Collider2D[] results) (at :0) UnityEngine.PhysicsScene2D.OverlapCollider (UnityEngine.Collider2D collider, UnityEngine.ContactFilter2D contactFilter, UnityEngine.Collider2D[] results) (at :0) UnityEngine.Collider2D.OverlapCollider (UnityEngine.ContactFilter2D contactFilter, UnityEngine.Collider2D[] results) (at :0) Collidable.Update () (at Assets/scripts/Collidable.cs:18) Weapon.Update () (at Assets/scripts/Weapon.cs:34)
>> Collidable.cs: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Collidable : MonoBehaviour { public ContactFilter2D filter; private BoxCollider2D boxCollider; private Collider2D[] hits = new Collider2D[10]; protected virtual void Start() { boxCollider = GetComponent(); } protected virtual void Update() { boxCollider.OverlapCollider(filter, hits); for (int i = 0; i < hits.Length; i++) { if(hits[i] == null) continue; OnCollide(hits[i]); hits[i] = null; } } protected virtual void OnCollide(Collider2D coll) { Debug.Log("OnCollide was not implemented in " + this.name); } }
> Weapon.cs: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Weapon : Collidable { //Damage structure public int[] damagePoint= { 1,2 ,3 ,4 ,5 ,6 ,7 }; public float[] pushForce = {2.0f, 2.2f, 2.5f, 3f, 3.2f, 3.6f, 4f }; //upgrade public int weaponLevel = 0; private SpriteRenderer spriteRenderer; //swing private Animator anim; private float cooldown = 0.5f; private float lastSwing; private void Awake() { spriteRenderer = GetComponent(); } protected override void Start() { base.Start(); spriteRenderer = GetComponent(); anim = GetComponent(); } protected override void Update() { base.Update(); if(Input.GetKeyDown(KeyCode.Mouse0)) { if (Time.time - lastSwing > cooldown) { lastSwing = Time.time; Swing(); } } } protected override void OnCollide(Collider2D coll) { if(coll.tag == "Fighter") { if (coll.name == "Player") return; Damage dmg = new Damage { damageAmount = damagePoint[weaponLevel], origin = transform.position, pushForce = pushForce[weaponLevel], }; coll.SendMessage("ReceiveDamage", dmg); } } private void Swing() { anim.SetTrigger("Swing"); } public void UpgradeWeapon() { weaponLevel++; spriteRenderer.sprite = GameManager.instance.weaponSprites[weaponLevel]; } public void SetWeaponLevel(int level) { weaponLevel = level; spriteRenderer.sprite = GameManager.instance.weaponSprites[weaponLevel]; } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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