Add CT3536 Games Programming

This commit is contained in:
2023-12-07 02:05:57 +00:00
parent eb94d02f16
commit 71e1a59261
14438 changed files with 919425 additions and 0 deletions

View File

@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AsteroidScript : MonoBehaviour
{
public GameObject asteroid;
// Start is called before the first frame update
void Start()
{
// set asteroid start position to a random plae to the left of mars
asteroid.transform.position = new Vector3(-500,Random.Range(-250, 250),Random.Range(-250,250));
// adding force to the asteroir
asteroid.GetComponent<Rigidbody>().AddForce(Vector3.right * 200000 * Time.deltaTime);
}
// Update is called once per frame
void Update()
{
// destroy object if it goes off the right edge of the screen
Vector3 position = Camera.main.WorldToScreenPoint(transform.position);
if (position.x > Screen.width) {
Destroy(asteroid);
}
}
// destroy asterod upon collisions
void OnCollisionEnter() {
Destroy(asteroid);
}
}