Hello again, clever heads I again stuck on turning off components.
using UnityEngine;
using System.Collections;
public class AssignScripts : MonoBehaviour {
public Component Controller1;
public Component Controller2;
public Component Controller3;
public GameObject Obj1;
public GameObject Obj2;
public GameObject Obj3;
public GameObject Prefab1;
public GameObject Prefab2;
public GameObject Prefab3;
public Vector3 SpawnPoint1;
public Vector3 SpawnPoint2;
public Vector3 SpawnPoint3;
void Update() {
if(input.GetKeyDown("1")) {
Obj1 = Instantiate(Prefab1, SpawnPoint1, Quaternion.identity)as GameObject).gameObject;
Controller1 = Obj1.GetComponent<PlayerController1>();
if(input.GetKeyDown("2")) {
Obj2 = Instantiate(Prefab2, SpawnPoint2, Quaternion.identity)as GameObject).gameObject;
Controller2 = Obj2.GetComponent<PlayerController2>();
if(input.GetKeyDown("3")) {
Obj3 = Instantiate(Prefab3, SpawnPoint3, Quaternion.identity)as GameObject).gameObject;
Controller3 = Obj1.GetComponent<PlayerController3>();
}
}
}
In first script i assign Controller and in second script i want to disable that controller.
using UnityEngine;
using System.Collections;
public class DisableControllers : MonoBehaviour {
private AssignScripts assignScripts;
void Start() {
assignScripts = GetComponent<AssignScripts>();
}
void Update() {
if(input.GetKeyDown("q")) {
assignScripts.Controller1.enabled = false;
}
if(input.GetKeyDown("w")) {
assignScripts.Controller2.enabled = false;
}
if(input.GetKeyDown("e")) {
assignScripts.Controller3.enabled = false;
}
}
}
I know it doesnāt work since it says that UnityEngine.Component does not contain a definition for āenabledā. Iāve tried every combination, but nothing works. If there is not enough information, let me know.