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 Zacharianinjaa · Aug 30, 2012 at 04:22 AM · javascriptscenefinddoorsendmessage

Player wont be found on start

My current script is a script for a door collision. when the Distance reaches less then 1 the player is moved to a separate scene and to the spawn point in which is specified in the code. I am currently having problems with the player not being found and when i just assign the player manually the send message script does not find the its way to parent in which the second script is attached. The game object Trigger which the first code is attached to is the child of the Spawnpoint in which the Second script is attached. Thanks in advance

this is my code:

 var Player : Transform;
 var Inside : float = 1;
 
 var GoingToSpawnPNT : int = 0;
 
 var Dist : float;
 
 function Start()
 {
     Player = transform.Find("Player");
 }
 
 function Update()
 {
     if (Player != null)
     {
         var dist : float = Vector3.Distance(Player.position, transform.position);
         Dist = dist;
     
         if (dist < Inside)
         {
             Player = null;
             transform.root.gameObject.SendMessage("Assign", GoingToSpawnPNT);
            }
     }
 }

This is my Second code

 var CustomSpawnPoint : int;
 static var Spawn : int;
 
 var Level : String;
 
 function Update()
 {
     if (Spawn == CustomSpawnPoint)
     {
         Debug.Log("Spawned");
         Spawn = 0;
         //Create Character
     }
 }
 
 function Assign(SpawnNum : int)
 {
     Spawn = SpawnNum;
     Application.LoadLevel(Level);
 }
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 Kryptos · Aug 30, 2012 at 07:55 AM 0
Share

Using static variables to keep values between level is a bad habit. Consider using the singleton pattern ins$$anonymous$$d.

avatar image Zacharianinjaa · Aug 30, 2012 at 01:26 PM 0
Share

Alright thank you. i will try to fix that

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · Aug 30, 2012 at 05:22 AM

Well, I am a little confused on the hierarchy of your objects but my view would be to use a trigger instead of the first script and a reference to the script (I don't really fancy SendMessage but it is personal):

 var GoingToSpawnPNT:int = 0;
 var obj:cube ;
 function Start(){
 obj = GameObject.FindWithTag("Player").GetComponent(cube);
 }
 
 function OnTriggerEnter(other:Collider){
     if(other.gameObject.tag=="Player")obj.Assign(GoingToSpawnPNT);

}

Comment
Add comment · Show 1 · 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 Zacharianinjaa · Aug 30, 2012 at 01:14 PM 0
Share

Sorry if i did not clarify the hierarchy well enough. There are 2 objects Trigger and SpawnPoint Trigger is the child to SpawnPoint.

As for changing it to a collision, i found that that didnt work how i had liked so im using distance.

Do you have any idea as to why player is not being found?

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

9 People are following this question.

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

Related Questions

How to find a prefab in another scene? 1 Answer

Finding A Variable With A String Variable 1 Answer

How do I place a player in the right spot when I change scenes? 1 Answer

SendMessage script problem 2 Answers

Can't put Sendmessage to work. 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