A
A
Andy2132021-08-06 19:15:36
Unity
Andy213, 2021-08-06 19:15:36

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

1 answer(s)
A
Artyom, 2021-08-06
@Andy213

You have Transform in void Start with a capital letter. This is the name of the class, but you need to refer to the variable (transform)

private void Start() => character = GameObject.FindGameObjectWithTag("Player").transform;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question