Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [RequireComponent(typeof(Rigidbody))]
- public class Asteroid : MonoBehaviour
- {
- [Header("Inscribed")]
- public float speed = 10;
- public int numSplit = 2;
- [Header("Dynamic")]
- public int size = 3;
- // Start is called before the first frame update
- void Start()
- {
- Vector3 vel = Random.insideUnitCircle;
- if (vel.magnitude == 0)
- {
- vel = Random.insideUnitCircle;
- }
- vel.Normalize();
- vel *= speed / size;
- GetComponent<Rigidbody>().velocity = vel;
- transform.localScale = Vector3.one * (size / 3f);
- }
- // Update is called once per frame
- void Update()
- {
- }
- private void OnCollisionEnter(Collision collision)
- {
- bullet bull = collision.gameObject.GetComponent<bullet>();
- if (bull == null) return;
- bull.KillMe();
- if (size > 1)
- {
- for (int i = 0; i < numSplit; i++)
- {
- GameObject go = Instantiate<GameObject>(this.gameObject);
- Asteroid ast = go.GetComponent<Asteroid>();
- ast.size = size - 1;
- }
- }
- Destroy(gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement