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 eeveelution8 · Apr 26, 2014 at 09:21 PM · playererror messagerespawnhealth

Problems with a player spawning and handling script

Here's the script,

 var spawnpoints : GameObject [];
 
 var isalive : boolean = true;
 var playerprefab : GameObject;
 var player : GameObject;
 
 var Target : GameObject;
 
 InvokeRepeating("checkalive", 0, 0.0001);
 
 
 
 
 
 function checkifalive () {
 
     if(player.HP < 1){
     
     isalive == false;
     
     respawn();
     
     }
 
 
 }
 
 
 
 function FindTarget () : GameObject {
     if(GameObject.FindWithTag("Finish")){
         who = GameObject.FindWithTag("Finish"); //We have found a Target
     }
     return who;
 }
 
 function Update () {
 if(!Target){
         Target = FindTarget(); return;
     }
 }
 
 
 function respawn (){
 
 yield WaitForSeconds(3);
 
 
     var index : int = Random.Range(1,spawnpoints.length);
     var thespawn : GameObject = spawnpoints[index];
  
     var instance : GameObject = Instantiate(playerprefab, thespawn, transform.rotation);
     
     player = instance;

     isalive == true;
 
 
 }

there are two errors im encountering with this, and every time i think i fixed it, it gets worse, so I've stopped and resorted to unity answers and the guides.

How the script is supposed to work, is that the checkifalive function checks every one 10 thousandth of a second if the player gameobjects HP value is more than one. if it isnt, it checks the isalive boolean to false and respawns the player by using the playerprefab variable.

the respawn function supposedly should spawn the playerprefab randomly in one of the spawnpoints, and set the isalive value back to true.

there are two errors, the first is

Assets/scripts/Deathmatch/deathmatchHealth.js(19,17): BCE0034: Expressions in statements must only be executed for their side-effects.

and

Assets/scripts/Deathmatch/deathmatchHealth.js(52,44): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.GameObject, UnityEngine.GameObject, UnityEngine.Quaternion)' was found.

again, I'm not sure how to fix these without making it worse, any help is appreciated.

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 BlackHoleStorm · Apr 26, 2014 at 09:30 PM

You have your Instantiate outside of a function, so it isn't running.

So instead of this

 InvokeRepeating("checkalive", 0, 0.0001);

use

 function Start()
 {
 InvokeRepeating("checkalive", 0, 0.0001);
 }

or just add checkalive(); to your Update function

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 eeveelution8 · Apr 26, 2014 at 11:29 PM 0
Share

Didnt change anything or fix any errors

avatar image getyour411 · Apr 26, 2014 at 11:46 PM 0
Share

The first error because you have two equal signs (an equality test like an if) but you should only have one. The Invoke was an issue but that's fixed per your last comment, however an invoke that often to be honest is weird and should be rethought. Line 30 looks odd to me; Add

 #pragma strict 

to the very top of this and see if you get further or more info on errors.

Finally, thespawn is a GameObject but the 2nd argument should be a position like thespawn.transform.position

avatar image BlackHoleStorm · Apr 27, 2014 at 10:26 AM 0
Share

I've just read what getyour411 said and the only other problems I can see is you set "isAlive" with 2 equal signs as he said. I'm not really a JS guy so sorry I can't help much

avatar image eeveelution8 · Apr 27, 2014 at 09:26 PM 0
Share

thanks for the help you two :3

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

21 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 avatar image avatar image avatar image

Related Questions

Respawn Player after Health 0 1 Answer

Restart with GUIText 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

c# how to change player location on 0 hp 1 Answer

Taking a hit 3 Answers


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