-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoveController.cs
57 lines (52 loc) · 1.37 KB
/
MoveController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Com.Mygame;
public class MoveController : MonoBehaviour
{
readonly float move_speed = 20;
int moving_status;
Vector3 dest;
Vector3 middle;
void Update()
{
if (moving_status == 1)
{
transform.position = Vector3.MoveTowards(transform.position, middle, move_speed * Time.deltaTime);
if (transform.position == middle)
{
moving_status = 2;
}
}
else if (moving_status == 2)
{
transform.position = Vector3.MoveTowards(transform.position, dest, move_speed * Time.deltaTime);
if (transform.position == dest)
{
moving_status = 0;
}
}
}
public void setDestination(Vector3 _dest)
{
dest = _dest;
middle = _dest;
if (_dest.y == transform.position.y)
{
moving_status = 2;
}
else if (_dest.y < transform.position.y)
{
middle.y = transform.position.y;
}
else
{
middle.x = transform.position.x;
}
moving_status = 1;
}
public void reset()
{
moving_status = 0;
}
}