Guardian.cs
1.53 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Guardian : MonoBehaviour {
Rigidbody myRigidbody;
public float moveSpeed = 3f;
int count = 1;
private void Awake()
{
}
// Use this for initialization
void Start ()
{
myRigidbody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate ()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 1f))
{
//myRigidbody.AddTorque(Vector3.left);
transform.rotation = Quaternion.Euler(0, transform.localEulerAngles.y - 90f, 0);
//Quaternion.EulerAngles(0, transform.rotation.y - 90f, 0);
//Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward), Color.yellow);
Debug.Log("부딫힘: " + hit.collider.gameObject.name);
Debug.Log("각도: " + transform.localEulerAngles);
}
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) , Color.yellow);
myRigidbody.MovePosition(gameObject.transform.position + transform.TransformDirection(Vector3.forward) * moveSpeed * Time.deltaTime);
count = 1;
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "Player")
{
ScaleUpGameManager.Instance.GameOver();
}
}
}