-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTankMove2.cs
More file actions
29 lines (24 loc) · 832 Bytes
/
TankMove2.cs
File metadata and controls
29 lines (24 loc) · 832 Bytes
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
using UnityEngine;
using System.Collections;
public class TankMove : MonoBehaviour
{
public float speed = 1.5f;
private Vector3 target;
private Vector3 target_rot;
void Start()
{
target = transform.position;
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = transform.position.z;
target_rot = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
var angle = Mathf.Atan2(target_rot.y - transform.position.y, target_rot.x - transform.position.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0,0,angle + 90);
}
}