37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System.Collections;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CollideScript : MonoBehaviour
|
|
{
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
var earth = GameObject.Find("Earth").transform;
|
|
var meteor = transform;
|
|
|
|
//print($"The earth location: {earth.position}");
|
|
//print($"The meteor location: {meteor.position}");
|
|
|
|
var distance = Vector3.Distance(earth.position, meteor.position);
|
|
if (distance < (earth.lossyScale + meteor.lossyScale).magnitude/4) {
|
|
print("EXPLOSION!");
|
|
var vector = earth.position - meteor.position;
|
|
var relCollisionPoint = vector.normalized * meteor.lossyScale.magnitude/2;
|
|
var absCollisionPoint = meteor.position + relCollisionPoint;
|
|
|
|
var explosion = GameObject.Find("Explosion").transform;
|
|
explosion.position = absCollisionPoint;
|
|
explosion.GetComponent<ParticleSystem>().Play();
|
|
|
|
}
|
|
}
|
|
}
|