public class FirstPersonCharacterScript : MonoBehaviour {
public int lives = 3;
public Transform respawn;
public Transform fireFXFlameBall01;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter (Collider other)
{
if (other.transform == fireFXFlameBall01)
{
transform.position = respawn.position;
lives -= 1;
}
}
}
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.
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: 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:
if (other.gameObject.name == "fireFXFlameBall01")
{
//do stuff
}
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:
if (other.gameObject.tag == "fireball")
{
//do stuff
}
The Debug told me that I was staying on the same place, so I tried another code:
void OnTriggerEnter(Collider other)
{
if (other.transform == fireFXFlameBall01)
{
Debug.Log (transform.position = new Vector3(0,1,0));
lives-=1;
}
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?
Changed the code again, and still only lives is -1 and no return to basic.
void OnTriggerEnter (Collider col)
{
if (col.tag == "FireFXFlameBall01")
{
transform.position = new Vector3(0,1,0);
lives -= 1;
}
}
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.
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.