Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

No respawn.

Discussion in 'Scripting' started by jo6x, Feb 27, 2016.

  1. jo6x

    jo6x

    Joined:
    Jan 2, 2016
    Posts:
    113
    This is my script

    Code (CSharp):
    1. public class FirstPersonCharacterScript : MonoBehaviour {
    2. public int lives = 3;
    3.     public Transform respawn;
    4.     public Transform fireFXFlameBall01;
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.    
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update () {
    13.    
    14.     }
    15.     void OnTriggerEnter (Collider other)
    16.     {
    17.         if (other.transform == fireFXFlameBall01)
    18.         {
    19.             transform.position = respawn.position;
    20.             lives -= 1;
    21.         }
    22.     }
    23. }
    I created an empty object, this to make my FirstPersonCharacter to get to this place when it collides with the fireFXFlameBall01.
    The Lives do count -1, so that works, but the respawn to the empty object doesn't work.
     
  2. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    have you tried printing the respawn position and transfrom position to check?
     
  3. RavenOfCode

    RavenOfCode

    Joined:
    Apr 5, 2015
    Posts:
    869
    Use:
    Code (CSharp):
    1. if (other.gameObject.name == fireFXFlameBall01)
    2.         {
    3.             transform.position = respawn.position;
    4.             lives -= 1;
    5.         }
     
    Last edited: Feb 28, 2016
  4. jo6x

    jo6x

    Joined:
    Jan 2, 2016
    Posts:
    113
    Can you help me with that.

    @Raven, youre answer doesn't work, the name isn't allowed.
     
    Last edited: Feb 28, 2016
  5. RavenOfCode

    RavenOfCode

    Joined:
    Apr 5, 2015
    Posts:
    869
    What Laperen is trying to say is try using Debug.Log() to check if the transform.position and respawn.position are in fact the same, something like:
    Code (CSharp):
    1. Debug.Log (transform.position + "/" + respawn.position);
    This would tell you that you in fact are getting the respawn you just dont notice it.

    My bad I gave you the wrong code, what I meant to give you was this:
    Code (CSharp):
    1. if (other.gameObject.name == "fireFXFlameBall01")
    2.             {
    3.                      //do stuff
    4.             }
    This required the fireballs name to be fireFXFlameBall01 exactly.

    Another option you could think about is using tags, if you created a fireball tag for your fireball then you could use:
    Code (CSharp):
    1. if (other.gameObject.tag == "fireball")
    2.             {
    3.                      //do stuff
    4.             }
    For more information on tags see http://docs.unity3d.com/Manual/Tags.html.
     
  6. jo6x

    jo6x

    Joined:
    Jan 2, 2016
    Posts:
    113
    The Debug told me that I was staying on the same place, so I tried another code:

    Code (CSharp):
    1. void OnTriggerEnter(Collider other)
    2. {
    3. if (other.transform == fireFXFlameBall01)
    4. {
    5. Debug.Log (transform.position = new Vector3(0,1,0));
    6. lives-=1;
    7. }
    The Debug.Log says that the position changes to 0,1,0 like the script says, but the object FirstPersonCharacter doesn't move to that place.
    Still the problem is there, how to fix this?
     
  7. RavenOfCode

    RavenOfCode

    Joined:
    Apr 5, 2015
    Posts:
    869
    Debuging a new position doesnt change the transforms position, maybe try actually changing the position.
     
  8. jo6x

    jo6x

    Joined:
    Jan 2, 2016
    Posts:
    113
    By removind the debug, still it doesn't work.
    Hopefully there is a way to make this work, I can't.
     
  9. jo6x

    jo6x

    Joined:
    Jan 2, 2016
    Posts:
    113
    Changed the code again, and still only lives is -1 and no return to basic.

    Code (CSharp):
    1. void OnTriggerEnter (Collider col)
    2.     {
    3.         if (col.tag == "FireFXFlameBall01")
    4.         {
    5.             transform.position = new Vector3(0,1,0);
    6.             lives -= 1;
    7.         }
    8.     }
    Should this be the problem:
    There are inconsistent line endings in the 'Assets/FirstPersonCharacterScript.cs' script. Some are Mac OS X (UNIX) and some are Windows.
    This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands.
     
    Last edited: Feb 28, 2016
  10. RavenOfCode

    RavenOfCode

    Joined:
    Apr 5, 2015
    Posts:
    869
    May I suggest that you take a look at the learn section, there are plenty of tutorials that would show you how to fix simple problems like the one you are having.