S
S
Shameless192020-12-27 19:29:41
Unity
Shameless19, 2020-12-27 19:29:41

Where is the error in the movement of the object?

The script hangs on Canvas:

public class Test2 : Test1
{
 private GameObject inst;
    protected  GameObject GO;
    private static Vector2 destination;
    public static Vector2 Destination
    {
        get { return destination; }
        set 
        {          
            destination = value;           
        }
    }
void Start()
    {   
     GO = Resources.Load("W11", typeof (GameObject)) as GameObject;
     destination = RandomVector2(destination);
     Init();
    }
    public void Init()
    {
       inst = Instantiate(GO, destination, Quaternion.identity) as GameObject;
       inst.transform.SetParent(Canvas.transform, false);
       inst.transform.position = destination;
       StartCoroutine(TCoroutine()); //выставляет новое значение destination
    }
}


Another script is responsible for the movement of the object (hanging on the object itself):
public class Update1 : MonoBehaviour
{
    void Update()
    { 
       transform.position = Vector2.Lerp(transform.position, Test2.Destination, Test1.speed* Time.deltaTime);
    }
}


In this scenario, everything works correctly, but I need to move the Update function to the first script, and the problem is that when I try to paste there:
void Update()
    { 
       inst.transform.position = Vector2.Lerp(transform.position, destination, Test1.speed* Time.deltaTime);
    }

The object doesn't react the way it should - instead it shakes at one point.
How do I need to rewrite it so that everything works properly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Axian Ltd., 2017-02-26
@AxianLTD

Cool, two questions
1. Why are you opening the input file as "wb"? Do you write something in it?
2. Where in your code will the file be deleted? I don't see such a line. Or do I look bad?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question