Script 타겟 이동
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectMoveMapTrigger : MonoBehaviour {
public bool trigger = false;
public Vector3 targetPosition;
public float speed;
private void Update()
{
if (trigger)
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, targetPosition, step); // Move
if (transform.position == targetPosition)
trigger = false;
}
}
void OnTriggerEnter(Collider other)
{
// tag == "A" Object 충돌
if (other.tag == "A")
{
trigger = true;
targetPosition = other.transform.position; // Target Vector
}
}
}
| cs |
Script 타겟 이동 및 각도(수정)
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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectMoveMapTrigger : MonoBehaviour {
public bool trigger = false;
public Vector3 targetPosition;
public float speed;
public Transform target;
Vector3 vector3;
private void Update()
{
if (trigger)
{
if (x > 0) x--;
if (y > 0) y--;
if (z > 0) z--;
float step = speed * Time.deltaTime;
transform.eulerAngles = new Vector3(x,y,z);
transform.position = Vector3.MoveTowards(transform.position, targetPosition, step); // Move
if (transform.position == targetPosition)
trigger = false;
}
}
float x, y, z;
void OnTriggerEnter(Collider other)
{
// tag == "A" Object 충돌
if (other.tag == "A")
{
x = transform.eulerAngles.x;
y = transform.eulerAngles.y;
z = transform.eulerAngles.z;
trigger = true;
targetPosition = other.transform.position; // Target Vector
target = other.GetComponent<Transform>();
}
}
}
| cs |
댓글
댓글 쓰기