Hi Guys,
In this little game (i’m trying to learn the UFO project), i try to make my player teleport when he reaches count of 3. My player téléports, but i’m unable to make it move afterwards (lines 22 to 27 no longer works after the teleport). I think the error is in the lines 29 to 32, but i can’t find it ![]()
thanks for any input
Here is the script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour {
public float vitessedujoueur;
public Text countText;
public Text winText;
private Rigidbody2D rb2d;
private int count;
public Transform dest;
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
count = 0;
winText.text = "";
SetCountText();
}
void FixedUpdate()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector2 mouvement = new Vector2(horizontal, vertical);
rb2d.AddForce(mouvement * vitessedujoueur);
if (count >= 3)
{
this.gameObject.transform.position = dest.position;
Camera.main.transform.position = dest.position;
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("PickUp"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Count:" + count.ToString();
if (count >= 10)
winText.text = "BRAVO!";
}
}