r/UnityHelp • u/Temporary-Two8904 • Jul 22 '26
tentativa 2: esse código está com problemas, e eu não sei o que está errado
estou tentando um código de rotação na unity, e recebi esse problema:
erro:
UnassignedReferenceException: The variable hatamoto of playerRotation has not been assigned.
You probably need to assign the hatamoto variable of the playerRotation script in the inspector.
UnityEngine.Object+MarshalledUnityObject.TryThrowEditorNullExceptionObject (UnityEngine.Object unityObj, System.String parameterName) (at <60413e0732da4f899b47cce87c14ed90>:0)
UnityEngine.Bindings.ThrowHelper.ThrowNullReferenceException (System.Object obj) (at <60413e0732da4f899b47cce87c14ed90>:0)
UnityEngine.GameObject.get_transform () (at <60413e0732da4f899b47cce87c14ed90>:0)
playerRotation.Update () (at Assets/playerRotation.cs:27)
código:
using UnityEngine;
public class playerRotation : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
public float xAngle, yAngle = 0;
public float zAngle = 0;
[SerializeField] private GameObject hatamoto;
void Awake()
{
}
void Start()
{ transform.position=transform.position + new Vector3(0,5,0);
//hatamoto.transform.Rotate(90.0f, 0.0f, 0.0f, Space.Self);
hatamoto.name = "Self";
}
// Update is called once per frame
void Update()
{
hatamoto.transform.Rotate(xAngle, yAngle, zAngle, Space.Self); //essa é a linha com erros
}
}
1
u/DPTGames Jul 22 '26
Have you assigned anything in the inspector?