(I know there are many forums about this but nothing I tried doesn’t work)
I’m trying to disbale character controller script in update by key pressing
void Update(){
if(Input.GetKeyDown(KeyCode.E)){
GetComponent<CharacterController>().enabled = false;
}
}
First, I didn’t know why it is not working. I searched and I found that CharacterController is enabled by default.
I tried this
void Update(){
GetComponent<CharacterController>().enabled = false;
}
It woked but I need to condition this by key pressing.
I also tried with a secondary script:
DisableControll.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DisableController : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
GetComponent<CharacterController>().enabled = false;
}
}
and In main script:
GetComponent<DisableController>().enabled = true;
The DisableController doesn’t enable on key press