K
K
Kifoter2020-06-20 16:14:33
Unity
Kifoter, 2020-06-20 16:14:33

What should I do to make the code work?

Created a script in a unit, entered the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
public Transform SelfTransform;
void Update()
{
SelfTransform.Translate(0.1f, 0, 0);
}
}
attached to the character and get this error:
UnassignedReferenceException: The variable SelfTransform of NewBehaviourScript has not been assigned.
You probably need to assign the SelfTransform variable of the NewBehaviourScript script in the inspector.
UnityEngine.Transform.get_position() <0x38fe2290 + 0x0006a> in <6a3f68e4ae18416e9941eafa34caba8a>:0
UnityEngine.Transform.Translate (UnityEngine.Vector3 translation, UnityEngine.Space relativeTo) (at C:/buildslave/unity/build/Runtime/Transform/ScriptBindings/Transform.bindings.cs:118)
UnityEngine.Transform.Translate (System.Single x, System.Single y, System.Single z) (at C:/buildslave/unity/build/Runtime/Transform/ScriptBindings/Transform.bindings.cs:134)
NewBehaviourScript.Update () (at Assets/NewBehaviourScript.cs: 10)
What can I do to make it work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Pokrovsky, 2020-06-20
@Makaroshka007

The variable SelfTransform of NewBehaviourScript has not been assigned.
You probably need to assign the SelfTransform variable of the NewBehaviourScript script in the inspector

4
4xy0, 2020-06-20
@4xy0

The whole answer lies here
5eee3ee68f5ed113274209.jpeg
I join the answers above!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question