I’m wondering… how would you convert this code to C#? What kind of variable would target be?
var target=GameObject.Find("Main Camera").GetComponent("CameraScript").target;
I’m wondering… how would you convert this code to C#? What kind of variable would target be?
var target=GameObject.Find("Main Camera").GetComponent("CameraScript").target;
it would be the same type as ‘target’
Whatever “target” was declared as: it’s a custom property. Most likely in this case it would be a GameObject or a Transform, just depends what CameraScript defined it as.
GameObject target = GameObject.Find(“Main Camera”).GetComponent().target;
There’s not really anyway of telling from your example. “target” would have to be a public variable of the CameraScript MonoBehaviour. If CameraScript were written in C# you could just look what type it is. If it’s in javascript you have to look at what “target” is referring to… probably a GameObject, but that’s just a guess based on the script name.
If CameraScript is in C# and you are using an IDE with intellisense (Visual C#, probably MonoDevelop) then you could write
GetComponent().
as soon as you write the “.” it should show you the accessible properties and their types… The angle brackets have to do with “generics” which you can read up on at your leisure.
Thanks… turns out what I was doing wrong was having CameraScript in parentheses and not chevrons.