42 lines
864 B
C#
42 lines
864 B
C#
|
|
using UnityEngine;
|
|
|
|
public class Asteroid : MonoBehaviour
|
|
{
|
|
public float Speed = 0.5f;
|
|
public Vector3 RotatingSpeed ;
|
|
float timer;
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
transform.Translate(new Vector3(0,-Speed,0), Space.World);
|
|
|
|
transform.Rotate(RotatingSpeed);
|
|
|
|
timer += Time.deltaTime;
|
|
if(timer>8)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
Destroy(gameObject);
|
|
|
|
if(other.tag == "Player")
|
|
{
|
|
FindObjectOfType<GameManager>().GameOver();
|
|
}
|
|
else
|
|
{
|
|
FindObjectOfType<GameManager>().AddScore();
|
|
}
|
|
|
|
}
|
|
} |