How to stop movement script on void start and resume after.
Hello! I am having trouble getting this script to work.
What i want is: On Void Start (So the moment the scene starts) i want my movement to be disabled, then after a total of 12 seconds, i want my movement to be enabled again.
It's not that hard to do but i am still very new to coding and appriciate all help i can get! Thank you!
My script(c#):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterController : MonoBehaviour
{
private bool Movement;
public float speed = 10.0F;
// Use this for initialization
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
StartCoroutine(ActivateMovement());
Movement = false;
}
// Update is called once per frame
void Update()
{
if (Movement = true)
{
float translation = Input.GetAxis("Vertical") * speed;
float straffe = Input.GetAxis("Horizontal") * speed;
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
transform.Translate(straffe, 0, translation);
if (Input.GetKeyDown("escape"))
{
Cursor.lockState = CursorLockMode.None;
}
}
}
IEnumerator ActivateMovement()
{
yield return new WaitForSecondsRealtime(12);
Movement = true;
}
}
Comment