forked from StRobertCHSCS/ICS4U-PCP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNinja_StarController.cs
More file actions
38 lines (28 loc) · 920 Bytes
/
Ninja_StarController.cs
File metadata and controls
38 lines (28 loc) · 920 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
36
37
38
using UnityEngine;
using System.Collections;
public class Ninja_StarController : MonoBehaviour {
// set variables
public float star_speed;
public NewBehaviourScript scorpion; // call player script and set it to a variable
// Use this for initialization
void Start () {
scorpion = FindObjectOfType<NewBehaviourScript>();
if(scorpion.transform.localScale.x < 0)
{
star_speed = -star_speed;
}
}
// Update is called once per frame
void Update () {
GetComponent<Rigidbody2D>().velocity = new Vector2(star_speed, GetComponent<Rigidbody2D>().velocity.y);
}
// check to see if projectile hits enemy
void OnTriggerEnter2D(Collider2D star_collide)
{
if(star_collide.tag == "Enemy")
{
Destroy(star_collide.gameObject);
}
Destroy(gameObject);
}
}