-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCannon.cs
More file actions
35 lines (27 loc) · 811 Bytes
/
Cannon.cs
File metadata and controls
35 lines (27 loc) · 811 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
30
31
32
33
34
35
using UnityEngine;
using System.Collections;
public class Cannon : MonoBehaviour {
GameObject Player;
GameObject Cannonball;
float Timer = 1;
// Use this for initialization
void Start () {
Player = GameObject.Find("Player");
Cannonball = (GameObject)Resources.Load ("Cannonball");
}
// Update is called once per frame
void Update () {
transform.LookAt (Player.transform.position);
transform.eulerAngles = (new Vector3 (0f, transform.eulerAngles.y - 180f, 0f));
float dist = Vector3.Distance (transform.position, Player.transform.position);
if (dist <= 20) {
Timer -= Time.deltaTime;
if (Timer <= 0) {
Instantiate(Cannonball);
Cannonball.transform.position = transform.position;
Cannonball.transform.LookAt(Player.transform.position);
Timer = 1;
}
}
}
}