CAR ENTER EXIT
MY PLAYER GETS IN CAR BUT MY CAR DOENT WORK
HERES MY ERROR-NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value) car get in.Update () (at Assets/car get in.js:21)
AND
HERES MY SCRIPT -
var Car : Transform;
var player : Transform;
var exitPoint : Transform;
var doorTriggerLeft : Transform;
var PlayerCamera : Camera;
var CarCamera : Camera;
var isPlayerVisable : boolean;
function Update (){
if (Input.GetButtonDown("Fire1")&& isPlayerVisable){
//Make player invisable and still standing
player.gameObject.SetActiveRecursively(false);
player.gameObject.active = false;
// Parent player to ExitPoint
player.parent = exitPoint.transform;
player.transform.localPosition = Vector3(-1.5,2,0);
//Parent playerParent to car
exitPoint.parent = Car.transform;
exitPoint.transform.localPosition = Vector3(-0.5,2,0);
// Enable car as controllable object
GameObject.Find("Car").GetComponent("Car Control script").enabled = true;
PlayerCamera.enabled = false;
CarCamera.enabled = true;
}
else
{
if (Input.GetButtonDown("Fire1")){
// Make Character visable again.
player.gameObject.SetActiveRecursively(true);
player.gameObject.active = true;
// Unparent Player from everything.
player.transform.parent = null;
// Parent Exit Point to Door Trigger.
exitPoint.parent = doorTriggerLeft.transform;
// Disable car as a controllable
GameObject.Find("Car").GetComponent("DrivingScript").enabled = false;
PlayerCamera.enabled = true;
CarCamera.enabled = false;
}
}
}
function OnTriggerEnter(Player : Collider) {
isPlayerVisable = true;
}
function OnTriggerExit(Player : Collider) {
isPlayerVisable = false;
}
Answer by Brocccoli · Mar 17, 2016 at 02:52 PM
Seems your problem is on this line
GameObject.Find("Car").GetComponent("Car Control script").enabled = true;
I would seperate the calls into a few assignment statements, debug and make sure you're getting the correct values. One of them is currently null and this part
GetComponent("Car Control script")
look like the suspect. Is "Car Control script" really the name of the script attached to the game object? I don't think it is. Make sure you have this spelled correctly and EXACTLY as it appears in the Unity GUI.