So basically want I here an object with a collider and when the character walks through the collider, the object is moved to that object’s position via the armature. however I keep getting these errors every time the character enters the collider.
NullReferenceException: Object reference not set to an instance of an object
PickUp.collect () (at Assets/Scripts/PickUp.cs:19)
PickUp.LateUpdate () (at Assets/Scripts/PickUp.cs:13)
I can’t really pick up on what I’m doing wrong here and I’d appreciate some help :).
Here are my scripts.
inside the object with the collider:
using UnityEngine;
using System.Collections;
public class Grab : MonoBehaviour {
PickUp PickUpScript;
// Use this for initialization
void OnTriggerEnter(Collider other){
PickUpScript = other.GetComponentInParent<PickUp> ();
PickUpScript.grabbed = true;
PickUpScript.area = transform.position;
}
void OnTriggerExit(Collider other){
PickUpScript = other.GetComponentInParent<PickUp>();
PickUpScript.grabbed = false;
}
}
inside the character:
using UnityEngine;
using System.Collections;
public class PickUp : MonoBehaviour {
public bool grabbed;
public Animator anim;
public Vector3 area;
public Vector3 rotate;
void LateUpdate(){
if (grabbed) {
collect ();
}
}
void collect(){
Component armature = gameObject.GetComponent("Armature");
armature.transform.position = area;
}
}