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 Nynex71 · Jan 05, 2011 at 03:54 AM · positionvector3spawnteleport

Spawning System

I have a empty game object called "SpawnPoint". Obviously you probably know what im going to ask. I want people once there health = 0 to teleport here. Here is my script at this moment.

using UnityEngine; using System.Collections;

public class JobInfo : MonoBehaviour { public int curMoney = 1000; public int curHealth = 100; public int maxHealth = 100; public string curJob; public int Salary = 50; public int payTime = 180;

 public float healthBarLength;

 void Start () {     
     InvokeRepeating ("AddMoney", payTime, payTime);

     healthBarLength = Screen.width / 2;
 }

 // Update is called once per frame
 void Update () {        
     AdjustCurrentHealth(0);
     }
 void OnGUI() {

     GUI.Label (new Rect (10, 10, 100, 30), "Job:  ");
     GUI.Label (new Rect (35, 10, 100, 30), curJob);
     GUI.Label (new Rect (85, 10, 100, 30), "Salary:  ");
     GUI.Label (new Rect (125, 10, 100, 30),   Salary.ToString());
     GUI.Label (new Rect (155, 10, 100, 30), "Money:  ");
     GUI.Label (new Rect (200, 10, 100, 30),   curMoney.ToString());

     GUI.Box(new Rect(10, Screen.height - 30, healthBarLength, 20), curHealth + "/" + maxHealth);
     }

     public void AdjustCurrentHealth(int adj) {
             curHealth +=adj;

         if(curHealth < 1)
             curHealth = 0;

         if(curHealth > maxHealth)
             curHealth = maxHealth;

         if(maxHealth < 1)
             maxHealth = 1;
             healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
         }

     void AddMoney ()
         {
             curMoney += Salary;
         }


 }

Im guessing that it should start out like this...

if(curHealth = 0)
than something here.

I know ill need a variable, most likely or just to make stuff easier so would the variable look something like this?

public GameObject PlayerSpawn;

or would the variable have anything to do with Vector3? Im just looking for help and want to understand this more.

The SpawPoint is located at

X: 1613.222
Y: 1
Z: 1548.858

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by PrimeDerektive · Jan 05, 2011 at 03:59 AM

First off, try to use camelCase for vars and properties, and reserve CamelCase for functions and methods, its good practice. Then, make the variable

public Transform playerSpawn; 

Just so you have access to the transform component right off the bat, and drag the object from your scene hierarchy to the exposed playerSpawn var in the inspector. Then, in your if statement, do:

if(curHealth == 0)
    transform.position = playerSpawn.position;
Comment
Add comment · Show 4 · 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 PrimeDerektive · Jan 05, 2011 at 04:00 AM 0
Share

Note: I don't normally use C#, but I think my syntax is right.

avatar image Nynex71 · Jan 05, 2011 at 04:03 AM 0
Share

great and thanks for explaining it to me it really helps... and if you see see comment can u reply and tell me an example of when you would use a Vector3?

avatar image PrimeDerektive · Jan 05, 2011 at 04:12 AM 0
Share

well, transform.position IS a Vector3, its just a shortcut var of the transform component that tells you the current Vector3 position of that object in the scene.

avatar image Nynex71 · Jan 05, 2011 at 04:14 AM 0
Share

alright thanks :)

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

No one has followed this question yet.

Related Questions

Navmesh agent teleporting 3 Answers

Enemy spawn script/player position(java/js) 1 Answer

can I change float to vector3 on euler ?? 1 Answer

Snapping to Object Forward Axis 0 Answers

Player not spawning in right place. 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