Alrighty so I got the 1st part of it going smoothly. This is how I find my GameObjects RigidBody.
public Rigidbody2D CollidedOBJRB;
public void OnTriggerStay2D (Collider2D coll) {
if (coll.gameObject.tag == ("Player") && coll.gameObject.tag != HitBoxHere.tag
||
coll.gameObject.tag == ("CPU") && coll.gameObject.tag != HitBoxHere.tag) {
CollidedOBJRB = coll.GetComponent<Rigidbody2D>();
}
}
So basically if I collide with a certain Object of that If Statement.
My GameObject(CollidedOBJ) will equal to the Collided GameObject.
That works fine. I tested it BUT!
Then when I try to put the HitBoxScript and it’s Object into my other Script I get an Issue.
HitBoxScript Force = HitBox.GetComponent<HitBoxScript>();
//HitBox is a GameObject in my Currently used Script.
This Works fine too, No errors or nothing. But!
When I do something that allows me to change the Velocity I get some sort of annoying error for this line of Code.
Force.CollidedOBJRB.velocity = new Vector2(PushX,PushY);
NullReferenceException: Object reference not set to an instance of an object
CharacterCross.Combos () (at Assets/Characters/Cross/CharacterCross.cs:225)
CharacterCross.Update () (at Assets/Characters/Cross/CharacterCross.cs:841)
All in all, what I’m trying to do is, allow my HitBox to give force onto the CollidedOBJ Rigidbody by changing it’s velocity. But it seems, a little bug is getting in my way. What’s up with that?
Any Help would be appreciated, dudes.