И название файла скрипта в Unity должно быть равным названию класса!
public class MoneyEvent : MonoBehaviour{
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Animator PlayerAnimator;
public float MoveSpeed = 10f;
public float RotateSpeed = 5f;
private bool CanWalk = true;
public AudioSource Source;
public AudioClip[] StepSounds;
public bool MouseVisible = false;
private bool Pause = false;
public GameObject Cam;
public float CameraSpeed;
private float RotationY;
public Rigidbody PlayerBody;
private void FixedUpdate()
{
RotationY += -Input.GetAxis("Mouse Y") * Time.smoothDeltaTime * CameraSpeed;
Cam.transform.localRotation = Quaternion.Euler(RotationY, transform.localRotation.y, 0);
RotationY = Mathf.Clamp(RotationY, -30, 78);
if (MouseVisible)
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.Locked;
}
else if (!MouseVisible)
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.None;
}
if (Input.GetKeyDown(KeyCode.Escape))
{
MouseVisible = true;
}
else if(MouseVisible && Input.GetMouseButtonDown(0))
{
MouseVisible = false;
}
if (CanWalk)
{
transform.Rotate(new Vector3(0, Input.GetAxis("Mouse X"), 0 * Time.smoothDeltaTime * RotateSpeed), Space.World); // Camera Rotate
if (Input.GetKey(KeyCode.LeftShift))
{
MoveSpeed = 4f;
PlayerAnimator.speed = 1.3f;
}
else
{
MoveSpeed = 3f;
PlayerAnimator.speed = 1f;
}
if (Input.GetKey(KeyCode.W))
{
transform.Translate(transform.forward * Time.smoothDeltaTime * MoveSpeed, Space.World);;
PlayerAnimator.SetBool("Back", false);
PlayerAnimator.SetBool("Forward", true);
}
else if (Input.GetKey(KeyCode.S))
{
transform.Translate(-transform.forward * Time.smoothDeltaTime * MoveSpeed, Space.World);
PlayerAnimator.SetBool("Forward", false);
PlayerAnimator.SetBool("Back", true);
}
else
{
SetIdle();
}
}
}
IEnumerator DoorOpening()
{
yield return new WaitForSeconds(2f);
{
CanWalk = true;
StopCoroutine(DoorOpening());
}
}
private void SetIdle()
{
PlayerAnimator.SetBool("Back", false);
PlayerAnimator.SetBool("Forward", false);
PlayerAnimator.SetBool("Left", false);
PlayerAnimator.SetBool("Right", false);
}
}