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 ruinstarr · Aug 02, 2013 at 02:02 AM · cameraerrorplayercharactercontrollerspawn

How do I create an Initial Spawn Point?

I am trying to get rid of an error that I am getting involving my character and camera. the first line of my code is the error. This is from my camera script

 var Target = transform;

I saw a tutorial once a while back that said adding a spawn point will fix this error. But I can't find that anymore so I am asking the community to teach me a bit about how to make a spawn point.

Comment
Add comment · Show 2
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 robertbu · Aug 02, 2013 at 03:19 AM 0
Share

There is nothing wrong with this like of code unless Target is the name of another script. We need to see your code in context, or at least a small sample of code that compiles and exhibits the error you are struggling with.

avatar image ruinstarr · Aug 02, 2013 at 03:25 AM 0
Share

Ok this is the error I'm getting

InternalGetTransform can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, ins$$anonymous$$d move initialization code to the Awake or Start function.

This is my camera script

 var Target = transform;
 
 var distanceFromPlayer = 10;
 
 function LateUpdate() { transform.position = Target.position + Vector3(distanceFromPlayer,0,0 ); }

when I double click the error it loads monodevelop and highlights the first line.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Aug 02, 2013 at 03:36 AM

You can fix your error by breaking the assignment apart:

 var Target;
 Target = transform;
  

Or better yet:

 var Target;
 function Start() {
   Target = transform;
 }

But reading through your code, I don't believe either one is what you want to do. You want to do this:

var Target : Transform;

You can then drag and drop your player onto the 'Target' variable in the Inspector. Or you can find it:

 function Start() {
     Target = GameObject.Find("Player").transform;
 }

Note: variables should be named with a lower case first letter. This is the convention used my most of the programmers on this list, and it makes it easier for them to read and debug.

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 ruinstarr · Aug 02, 2013 at 03:50 AM 0
Share

Ok, I'll try that. Is the "Player" component based on the tag associated with my character or the actual name of the character?

avatar image ruinstarr · Aug 02, 2013 at 03:56 AM 0
Share

Tried all 3 suggestions and none of them have worked thus far. I guess I'll have to experiment around a bit more to find the answer.

avatar image robertbu · Aug 02, 2013 at 04:00 AM 0
Share

GameObject.Find() finds the name. If you want the tag, use GameObject.FindWithTag(). By not working do you mean it does not compile or does not do what you want?

avatar image ruinstarr · Aug 02, 2013 at 04:08 AM 0
Share

Whenever my target variable = transform I get the error saying that I can't set that as a variable but if I try the other suggestions, it removes the variable from my inspector thus making me unable to set the target as my player. When I use the GameObject.Find code, the camera just zooms out very quickly and doesn't follow my character at all.

avatar image robertbu · Aug 02, 2013 at 02:54 PM 0
Share

Based on your code, this is what I think you want:

 #pragma strict
 
 private var Target : Transform;
 var distanceFromPlayer = 10;
 
 function Start() {
     Target = GameObject.Find("Player").transform;
 }
  
 function Update() {
     transform.position = Target.position + Vector3(distanceFromPlayer,0,0 );
 }

Note your "Player" game object must be named "Player" with an upper case 'P'.

Show more comments
avatar image
0

Answer by ruinstarr · Aug 02, 2013 at 09:21 PM

Ok, so your script didn't work right for me either, but after some experimenting I did get it to work. Here is what I got

 public var Player : Transform;
 var distance = 10;
 
 function Update(){
 transform.position = Player.position + Vector3(distance, 0, 0);
 }

This is a working, error free script for a 2D or 2.5D sidescroller. For anyone that needs a script for camera this one works flawlessly.

Comment
Add comment · 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

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

14 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

Related Questions

Problem with spawn player with RPC calls(c #) 1 Answer

For some reason when i start the game my players go out of the camera zone ? or they get invisible ? 0 Answers

CharacterController.isGrounded script error 0 Answers

c# set main camera to player (multiplayer) 1 Answer

Camera cannot find instantiated player 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