- Home /
How to get back player control?
3d runner, player just stays and the environment moves towards him. The player should jump through the rings, kind of like a tiger in Madagascar 3. If he catches a boost, all the rings lining up, so he just goes through them real fast for a couple of seconds. You can't control the player and his velocity = 0 at this moment. But, after, when I say Invoke the function which brings the control back in 3 sec, It doesn't work and player keeps being uncontrollable.
Thanks in advance. Boost script: public class PillBoost : MonoBehaviour {
public GameObject sparks;
public GameObject ring01;
bool isOnTrigger = false;
public void OnTriggerEnter(Collider other){
if (other.tag == "Player") {
isOnTrigger = true;
Instantiate (sparks,transform.position, Quaternion.identity);
Destroy (this.gameObject);
GameObject[] ringsArray = GameObject.FindGameObjectsWithTag("Ring");
GameObject P = GameObject.FindWithTag("Player");
for (int i=0;i<ringsArray.Length;i++){
Vector3 ringPos = ringsArray[i].transform.position;
Destroy(ringsArray[i]);
Instantiate(ring01,new Vector3(P.transform.position.x,P.transform.position.y-2,ringPos.z),Quaternion.identity);
}
GameObject.FindWithTag ("Player").GetComponent<PlayerController> ().canControl = false;
GameObject.FindWithTag ("Player").GetComponent<PlayerController> ().gravity = Vector3.zero;
GameObject[] rings01 = GameObject.FindGameObjectsWithTag ("Ring");
for (int i=0; i<rings01.Length; i++) {
rings01 [i].GetComponent<MoveScript> ().moveSpeed = new Vector3 (0, 0, -100);
}
}
}
void Update () {
if (isOnTrigger) {
Invoke ("StartPlayerController",3);
}
}
void StartPlayerController(){
GameObject.FindWithTag ("Player").GetComponent<PlayerController> ().canControl = true;
GameObject.FindWithTag ("Player").GetComponent<PlayerController> ().gravity = new Vector3 (-Input.acceleration.x * 80, 80, 0);
}
}
Your answer
Follow this Question
Related Questions
Subtract one from health every five seconds. 1 Answer
MMD How to export model and animations to Unity as 3rd person controller? 2 Answers
function OnTriggerEnter --> if -->if --> Invoke... well, it doesn't work! 2 Answers
Pause Menu upon Idle (timer & button issues C#) 0 Answers
Respawning a player after a certain amount of time 0 Answers