Question by
ISNOT1 · Aug 13, 2020 at 07:03 PM ·
oncollisionenterreference-other-object
how do i reference a float from another game object's script using onCollisionEnter?
hello, i'm making a game which includes realistic armour penetration behaviour but i'm having a little bit of trouble with my code when the bullet impacts the armour plate, here is the error that occurs on impact:
NullReferenceException: Object reference not set to an instance of an object bullet.OnCollisionEnter (UnityEngine.Collision other) (at Assets/Scripts/bullet.cs:40)
and here is the cutout of what is not working:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bullet : MonoBehaviour
{
private Armour t;
private void OnCollisionEnter(Collision other)
{
target = other.gameObject.GetComponent<Armour>().t;
}
}
Comment
Your answer
