- Home /
c# parsin error
Hey. I get a parsing error with this script.
using UnityEngine;
public class cameraFollow(){
public float LockedZ = 0;
public GameObject player;
void Update(){
transform.position = new Vector3(player.transform.x, LockedZ);
}
}
can you guys help me?
Exactly what type of parsing error is it? You aren't using System.Collections - that could be something.
Answer by Raph3004 · Aug 11, 2013 at 11:10 PM
If that script is a copy-paste of what you have than I'd look at your class declaration.
Assuming you're using C#
this: public class cameraFollow(){...}
should be this: public class cameraFollow : MonoBehaviour{...}
or if you don't want to inherit from MonoBehaviour it would be: public class cameraFollow{...}
try that.
and @ save. While I agree that if you're initializing a Vector3 you should use x,y,z... it is a vector3 after all. However, there is an overload for a V3 constructor that takes just x and y.
.- Raph -
This is the code after some updates.
using UnityEngine;
using System.Collections;
public class CameraFollow : $$anonymous$$onoBehaviour {
public float x;
public float y;
public float z;
public GameObject player;
void Update(){
transform.position = new
Vector3(player.transform.x, player.transform.y, player.transform.z); } }
should work. Well, your camera will be at the player's pivot point anyway.
Don't know why you declared the x,y and z floats, since your aren't using them though.
I also got a error that says: Type UnityEngine.Transform' does not contain a definition for
x' and no extension method x' of type
UnityEngine.Transform' could be found (are you missing a using directive or an assembly reference?)
and the same with y and z with the same code.
thanks in advance
I also got a error that says: Type UnityEngine.Transform' does not contain a definition forx' and no extension method x' of typeUnityEngine.Transform' could be found (are you missing a using directive or an assembly reference?)
Read what the error says. The data type transform doesn't have an x,y,z. If you're trying to get position than you would want
transform.position = new Vector3(player.transform.position.x, player.transform.position.y, player.transform.position.z);
and jonaks13 is correct, that will place the camera at the gameobject player's exact position. You may consider using an offset to put the cam in a more desirable location.
also, if that worked for you then go ahead and click thumbs up.
.- Raph -
thanks that worked, but how can I get it to not be in the exact position?