Hello everyone, Can anyone tell whats wrong with my Script? The Void Start does not Work. I was trying to enable/disable Script Components with this Script So i guess the Scriptable Object does not belong there, I was just trying out. For more Information Comment but ill answer tomorrow. ~Glemau Code (CSharp): using UnityEngine; using System.Collections; public class Switch : MonoBehaviour { public GameObject gb; public GameObject go; public Transform trans; private bool inCar = false; public Transform door; private ScriptableObject Control; private ScriptableObject UserControl; private ScriptableObject Audio; void Start () {//This part does not work! Control = gb.GetComponent<Car Controller>(ScriptableObject);//Unexpected Symbol Controller UserControl = gb.GetComponent<Car UserControl> (ScriptableObject);//Unexpected Symbol User Audio = gb.GetComponent<Car Audio> (ScriptableObject);//Unexpected Symbol Object } void Update () { if (Input.GetKeyDown (KeyCode.F) & inCar == false) { inCar = true; go.SetActive(true); } else if (Input.GetKeyDown (KeyCode.F) & inCar == true) { inCar = false; go.SetActive(false); trans.transform.position = door.transform.position; } } }
GetComponent works fine, as it always has. Your syntax, however, is wrong. You don't put anything in the parentheses; it's just GetComponent<Type>(). When using the generic version, there are no parameters. --Eric
In addition, your class names wont work because you have spaces in them. "CarAudio" not "Car Audio". Syntax is important. Furthermore, scriptableObjects are not components, so you could not use GetComponent to find them. Scriptable objects exist because they work with serialization, so you should use serialization to allocate them.
Sounds to me like you should start with some foundational skills and work your way up! Learn some C#, learn about how unity works, and these kinds of problems will be easy for you. Start here: https://unity3d.com/learn/tutorials/topics/scripting
The main issue is that your current code makes no sense and there is obviously a lack of understanding. And this tutorial from the learn scripting section should help you with that: http://unity3d.com/learn/tutorials/modules/beginner/scripting/getcomponent?playlist=17117