Answer the question
In order to leave comments, you need to log in
How to fix error CS1061 in unity?
Hello everyone, while programming, I got the error
error CS1061: 'GameObject' does not contain a definition for 'Transform' and no accessible extension method 'Transform' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?) Please help me fix it.
Here is the code:
using UnityEngine;
public class FirstPersonMovment : MonoBehaviour
{
[Space]
[SerializeField] private float mouseSensitivity = 1f;
[SerializeField] private float smooth = 2f;
[Space]
[SerializeField] private float minClamp = 90f;
[SerializeField] private float maxClamp = -90f;
Transform character;
private Vector2 currentMouseLook;
private Vector2 appliedMousedelta;
Ошибка:private void Start() => character = GameObject.FindGameObjectWithTag("Player").Transform;
private void Update()
{
var smoothMouseDelta = Vector2.Scale(new Vector2(
Input.GetAxisRaw ("Mouse X"), Input.GetAxisRaw ("Mouse Y")), Vector2.one * mouseSensitivity * smooth);
appliedMousedelta = Vector2.Lerp(appliedMousedelta, smoothMouseDelta, 1 / smooth);
currentMouseLook += appliedMousedelta;
currentMouseLook.y = Mathf.Clamp(currentMouseLook.y, -minClamp ,maxClamp);
character.localRotation = Quaternion.AngleAxis(currentMouseLook.x, Vector3.up);
transform.localRotation = Quaternion.AngleAxis(-currentMouseLook.y, Vector2.up);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question