- Home /
Dragging object inside TriggerZone
Im not sure if anyone has asked this before, havent found any spesific answers. I want to be able to throw a ball when the ball is inside a "ThrowZone" Trigger, but on the same time i want my DragRigidbody script to be disabled when on the outside of the "ThrowZone". The DragRigidbody script is added to my Player object, but this code does not seem to work. "Object referance not set to an instance of an object" :/ any help will be greatly appreciated :)
This is my "ThrowZone" script that is attached to the ThrowZone trigger.
var Script : DragRigidbody;
function OnTriggerEnter(col : Collider) {
if(col.gameObject.tag == "Player") {
Script = GetComponent(DragRigidbody);
Script.enabled = true;
}
}
function OnTriggerExit(col : Collider) {
if(col.gameObject.tag == "Player") {
Script = GetComponent(DragRigidbody);
Script.enabled = false;
}
}
function Start () {
}
function Update () {
}
Appreciate all help, should be able to solve this, but just cant see what im doing wrong at the moment!
Please format your code. Use the 101/101 button and also fix the indenting. Difficult to read code is less likely to get an answer.
Double click on the error in Unity's Console window and it will take you to line that has the error to make sure the issue is with DragRigidbody.
Test the 'Script' variable after you do the GetComponent() to see if it is null.
Select the player in the Inspector while the script is running to make sure your DragRigidbody script is not being deleted.