[Edited for more precision]
Hello !
I've a "playerObject" (that is a prefab, with a rigidbody [gravity set to true]) and when i enter a specific collider (where this script is attached to), i need this "playerObject" to be attached to a Collider (named "balaisColliderObject" in my script) i've add to a broom that is falling.
I've tried this solution :
var playerObject : GameObject;
var pousseurObject : GameObject;
var balaisColliderObject : GameObject;
var attach = false;
function Start () {
playerObject = gameObject.Find("Cesareredim 1");
pousseurObject = gameObject.Find("ColliderPousseur");
balaisColliderObject = gameObject.Find("ColliderBalaisCesare");
}
function OnTriggerEnter (other : Collider){
if(other.collider.gameObject == playerObject){
pousseurObject.rigidbody.AddForce(Vector3.forward * 100);
attach = true;
}
}
function Update (){
if (attach == true){
playerObject.transform.parent = balaisColliderObject.transform;
playerObject.transform.localPosition = balaisColliderObject.OwnerPosition;
}
}
But when i enter the collider, it gives me the "NullReferenceException: Object reference not set to an instance of an object" error. Is there some problem with the objects i'm calling or something like that (i think it's because of the hierarchy change of the object "Cesareredim 1" but i'm not sure of it) ?
Thanks !
↧