Answer the question
In order to leave comments, you need to log in
How to fix code in Unity?
Wrote a code that makes the object move smoothly horizontally "back and forth".
And this case is far from professional.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NailBoard : MonoBehaviour {
public GameObject nail;
public float moveto; //смещение на...
private bool toright = false; // Направлено в право?
void Start ()
{
}
void Update ()
{
if (toright == false)
{
nail.transform.position.x + (moveto * Time.DeltaTime);
toright = true;
}
else
{
nail.transform.position.x - (moveto * Time.DeltaTime);
toright = false;
}
}
}
Answer the question
In order to leave comments, you need to log in
It's not hard to describe what's wrong with you.
You add two numbers (in your case, the offset and the current position), but you don't write down the total value of this addition anywhere. c# doesn't like that. You need to write down the result somewhere, obviously in a position.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question