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 Kebabs · Mar 10, 2014 at 05:54 PM · transformpositioncontrolsrespawnstate

Controls stop when player respawns

Hi I am working on a basic respawn which just moves the player when they meet the condition to die. The test cube re-appears as intended but for some reason the controls seem to suddenly stop when the cube re-positions itself to the co-ordinates stated.

Was just wondering if anyone had any ideas looking at my script what is causing this to occur. I am using states as I find them to be very useful in helping me organize my code blocks. Thankful for any help offered.

using UnityEngine; using System.Collections;

public class Player2 : MonoBehaviour { public enum State { Playing, Dyng, } public static State currentState = State.Playing; private Transform Player; public static float playerSpeed; public static float playerStrength; public static bool hasDied = false;

 // Use this for initialization
 void Start () {
     Player = transform;
     Player.transform.position = new Vector3 (0, 1, 0);
     playerSpeed = 5.0f;
     playerStrength = 2.5f;
 
 }
 
 // Update is called once per frame
 void Update () {
     if (currentState != State.Dyng) {
         Player.Translate (Vector3.right * playerSpeed * Input.GetAxis ("Horizontal") * Time.deltaTime);
         Player.Translate (Vector3.up * playerSpeed * Input.GetAxis ("Vertical") * Time.deltaTime);
             }
     if (newLiftMechanic.inContact) {//used to check if the player is touching an object that can be lifted
                     playerSpeed = 0.0f;
             } else {
         playerSpeed = 5.0f;
             }
     if (hasDied) {
         StartCoroutine(Died());
             }
 }
 IEnumerator Died(){
     currentState = State.Dyng;
     renderer.enabled = false;
     Player.transform.position = new Vector3 (0, 1, 0);
     yield return new WaitForSeconds (0.5f);
     currentState = State.Playing;
     renderer.enabled = true;
             }

}

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
0
Best Answer

Answer by Zentiu · Mar 10, 2014 at 06:17 PM

hmm..

try resetting your playerSpeed in your IEnumerator somewhere like:

 currentState = State.Playing;
 playerSpeed = 5.0f;
 renderer.enabled = true;

see if that solves the problem.

also turn off the coroutine with:

 hadDied = false;
 StopCoroutine(died());


in your IEnumerator just after you enable the renderer.

hope this helps.

Comment
Add comment · Show 2 · 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 Kebabs · Mar 10, 2014 at 06:28 PM 0
Share

Thank you. This worked but the StopCoroutine gave me this error - error CS1502: The best overloaded method match for `UnityEngine.$$anonymous$$onoBehaviour.StopCoroutine(string)' has some invalid arguments, but ultimately this has helped!!

Thank you so much for your assistance.

avatar image Zentiu · Mar 10, 2014 at 06:32 PM 0
Share

my bad.. I copied it.. it should've been StopCoroutine("Died");

at least my answer was partially useful :P. glad it worked.

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 question 2 Answers

How do I make one transform rotation the same as anothers? 2 Answers

Getting an object to re-spawn/ transform player back to the beginning 1 Answer

Objects with same position appear in different places 2 Answers

Offset against Rotated Object,Applying Offset to a Rotated Transform 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