How to change FirstPerson Controller Speed OnTriggerEnter event for a certain amount of time?
Hey there,
So, im a complete noob with Unity, i got some of the basics and im in front of a problem that lies far beyond my curent understanding of using C#.
There's a standard asset FPSController that is tagged as "Player" that i want to freeze when passing through a door ("ZoneArrivee") for 4s to play a music and load NextLvl. By searching ive read that it's better to change the Controller speed in it's script than disabling First Person Controller (Which i tried and didn't worked), and after hours of testing multiple things i come here with the following script attached to my "ZoneArrivee" (which is a cube with a rigid body and triggered box collider) :
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
public class ZoneArrivee : MonoBehaviour
{
public AudioClip SoundVictory;
public string LevelToLoad;
public CharacterController controller;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
controller = GetComponent<CharacterController>();
float moveSpeed = 0f;
Vector3 relativeForward = transform.TransformDirection(Vector3.forward);
controller.Move(relativeForward * moveSpeed * Time.deltaTime);
StartCoroutine("Win");
}
}
IEnumerator Win()
{
GetComponent<AudioSource>().PlayOneShot(SoundVictory);
yield return new WaitForSeconds(4);
SceneManager.LoadScene(LevelToLoad);
}
}
With that, by passing through the door, i got : "There is no 'CharacterController' attached to the "ZoneArrivee" game object, but a script is trying to access it. You probably need to add a CharacterController to the game object "ZoneArrivee". Or your script needs to check if the component is attached before using it. UnityEngine.CharacterController.Move (UnityEngine.Vector3 motion) <0x181cf5f0 + 0x0005a> in :0 ZoneArrivee.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Script/ZoneArrivee.cs:20)"
While my FPS Controller is actually attached to the Controller space in the inspector for "ZoneArrivee". An helpful hand on how to call the speed of the Controller and how the whole thing work would be really appreciated since anything i find isn't really clear on how to do it (my comprehension in cause).
Your answer
Follow this Question
Related Questions
How to make my powerup last for about five seconds then go back to normal? 3 Answers
How to Get Speed to Very Gradually Pick Up Over Time? 2 Answers
Is Something Wrong With My Singleton Pattern? 1 Answer
How can I use "animator.SetTrigger()" if "animator.SetBool()" has been true for X amount of seconds? 0 Answers
I need my timer to only start after it hits a trigger. Please help! 0 Answers