Hello, I am new to Unity and came across a problem with trying to disable a script. I am trying to disable a script that is in the Car game object, but my script is also in the Car game object, I have tried everything that I could find on the internet but it didn’t work, I get the errors, The type or namespace “Script” could not be found, Are you missing a directive or an assembly reference?
How could I fix this?
This is my code:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Car : MonoBehaviour {
int inCar=0;
int count=0;
float axisX;
float axisY;
float axisZ;
float dist;
public Transform Car1;
public Transform FirstPersonController;
public Rigidbody Car1RigidBody;
public Camera CarCam;
public Camera FirstPersonControllerCam;
public Text CarGetIn;
public Button CarGetInBut;
public Text CarGetOut;
public Button CarGetOutBut;
public AudioListener AudListen;
public AudioListener AudListenFirstPerson;
public N20 n20;
// Use this for initialization
void Start () {
Car1 = Car1.GetComponent<Transform> ();
FirstPersonController = FirstPersonController.GetComponent<Transform> ();
CarCam = CarCam.GetComponent<Camera> ();
FirstPersonControllerCam = FirstPersonControllerCam.GetComponent<Camera> ();
CarGetIn = CarGetIn.GetComponent<Text> ();
CarGetInBut = CarGetInBut.GetComponent<Button> ();
CarGetOut = CarGetOut.GetComponent<Text> ();
CarGetOutBut = CarGetOutBut.GetComponent<Button> ();
Car1RigidBody = Car1RigidBody.GetComponent<Rigidbody> ();
AudListen = AudListen.GetComponent<AudioListener> ();
AudListenFirstPerson = AudListenFirstPerson.GetComponent<AudioListener> ();
N20 = GetComponent<N20>();
CarGetIn.enabled = false;
CarGetInBut.enabled = false;
CarGetOut.enabled = false;
}
void Update (){
if (inCar == 0) {
dist = Vector3.Distance(Car1.position, FirstPersonController.position);
if (dist < 5.00) {
CarGetIn.enabled = true;
CarGetInBut.enabled = true;
//print ("Test");
} else {
CarGetIn.enabled = false;
CarGetInBut.enabled = false;
// Car1.GetComponent<
// print ("Test");
}
//print (dist);
// Car1RigidBody.constraints = RigidbodyConstraints.FreezeAll;
AudListen.enabled=false;
AudListenFirstPerson.enabled=true;
AudListen.enabled=false;
n20.enable=false;
} else {
CarGetOut.enabled=true;
CarGetOutBut.enabled=true;
count=0;
AudListen.enabled=true;
n20.enable=true;
}
}
public void EnterCar(){
inCar = 1;
Car1.gameObject.SetActive (true);
CarCam.enabled = true;
FirstPersonController.gameObject.SetActive (false);
FirstPersonControllerCam.enabled = false;
CarGetIn.enabled = false;
CarGetInBut.enabled = false;
/*
Car1RigidBody.constraints &= ~ RigidbodyConstraints.FreezeAll;
*/
}
public void LeaveCar() {
inCar = 0;
//Car1.SetActive (false);
CarCam.enabled = false;
FirstPersonController.gameObject.SetActive (true);
FirstPersonControllerCam.enabled = true;
CarGetOut.enabled = false;
CarGetOutBut.enabled = false;
// Car1RigidBody.constraints = RigidbodyConstraints.FreezeAll;
}
}
Of course I have the start function, but I don’t want to make the post too long.
Thank,
Marcell