hello everyone!
i'm trying to create a ‘disable’ method in the player movement script so that when certain things happen in other scripts, the method is called and the player stops moving. for instance, player dies = movement disabled. i've created a short method inside the ThirdPersonMovement script called Disable that contains a bool “disabled”, which inside the method is set to true.
afterwards i took all of the movement script and put it inside an if(!disable) statement. so far so good.
now i'm trying to call this method from a different script, by using ThirdPersonMovement.Disable(true); but i get an error saying "no overload of method ‘Disable’ takes 1 argument.
thanks, here is the movement script:
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.Threading;
using UnityEngine;
public class ThirdPersonMovement : MonoBehaviour
{
public CharacterController controller;
public Transform cam;
public float speed = 6f;
public float turnSmoothTime = 0.01f;
float turnSmoothVelocity;
bool disabled;
void Update()
{
if (!disabled)
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if (direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
controller.Move(moveDir.normalized * speed * Time.deltaTime);
}
}
}
public void Disable()
{
disabled = true;
}
}