forked from StRobertCHSCS/ICS4U-PCP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectileController.cs
More file actions
44 lines (32 loc) · 1.08 KB
/
ProjectileController.cs
File metadata and controls
44 lines (32 loc) · 1.08 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
using UnityEngine;
using System.Collections;
public class ProjectileController : MonoBehaviour {
public float speed;
public mario player;
public LevelManager levelManager;
public LevelManager2 levelManager2;
// Use this for initialization
void Start () {
player = FindObjectOfType<mario>();
if (player.GetComponent<Rigidbody2D>().velocity.x < 0)
speed = -speed;
levelManager = FindObjectOfType<LevelManager>();
levelManager2 = FindObjectOfType<LevelManager2>();
}
// Update is called once per frame
void Update () {
GetComponent<Rigidbody2D>().velocity = new Vector2(speed, GetComponent<Rigidbody2D>().velocity.y);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.name == "mario")
{
levelManager.RespawnPlayer();
}
if (other.name == "mario2")
{
levelManager2.RespawnPlayer();
}
Destroy (gameObject);
}
}