Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jonaks13 · Aug 11, 2013 at 04:55 PM · c#parsing error

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cmpgk1024 · Aug 11, 2013 at 08:11 PM 0
Share

Exactly what type of parsing error is it? You aren't using System.Collections - that could be something.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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 -

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jonaks13 · Aug 12, 2013 at 06:53 AM 0
Share

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); } }

avatar image Joyrider · Aug 12, 2013 at 06:55 AM 0
Share

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.

avatar image jonaks13 · Aug 12, 2013 at 07:03 AM 0
Share

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

avatar image Raph3004 · Aug 12, 2013 at 02:51 PM 0
Share

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 -

avatar image jonaks13 · Aug 12, 2013 at 03:18 PM 0
Share

thanks that worked, but how can I get it to not be in the exact position?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

i am pretty sure that this is right but..... 1 Answer

Making a bubble level (not a game but work tool) 1 Answer

An OS design issue: File types associated with their appropriate programs 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges