using UnityEngine;
using System.Collections;
public class MYCLASSNAME : MonoBehaviour {
GameObject follow;
void LateUpdate (){
FIXME_VAR_TYPE cam= GetComponent<"Camera">();
if(cam != null)
{
if(follow)
{
cam.transform.position = Vector3(follow.transform.position.x, cam.transform.position.y, follow.transform.position.z);
}
}
}
}
And this is not working unfortunately :/.
So im Stuck, because this script in C# doesnt work :/… Any idea? I thought that cam should be bool type but this is not that simple :P. When I set bool cam = Get… I got error error CS1525: Unexpected symbol `)’ - this error was pointing at “bool cam = GetComponent<“Camera”>();”
Because I decided to use C# in my games(I knew some basics from C/C++). And I think that it could be handful If I wanna use it in near future with XNA for example.
And C# is C#. I know that using JS could be simpler becaue of many things but C# is my choice :P. Is bad decision :(?
Bad Luck, that many tutorials comes with JS not C#, so I decided to try convert them to C#.
cam = GetComponent();
?
But I think that not - get some errors about “The name `cam’ does not exist in the current context” pointing at :
“cam.transform.position = Vector3(follow.transform.position.x, cam.transform.position.y, follow.transform.position.z);”
Could anyone help my get properly working script :)?
Though I prefer to declare cam outside of the function and just pass in the component in Start/Awake so you don’t have to call GetComponent repeatedly.
EDIT
Also, if you want to check if the game object follow is null, you can’t do if(follow). You need to write it as if(follow != null).
Now I have only 1 error: “Expression denotes a type', where a variable’, value' or method group’ was expected” and this error is pointing at “cam.transform.position = Vector3(follow.transform.position.x, cam.transform.position.y, follow.transform.position.z);”