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 Bullet : MonoBehaviour
{
public GameObject bullet;
public float speed = 20f;
// Start is called before the first frame update
void Start()
{
// set the bullet moving
bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * speed;
// start periodically checking for being off-screen
InvokeRepeating ("CheckScreenEdges", 0.2f, 0.2f);
}
// Update is called once per frame
void Update()
{
}
private void CheckScreenEdges() {
Vector3 pos = bullet.transform.position;
Vector3 vel = bullet.GetComponent<Rigidbody>().velocity;
if (pos.x < GameManager.screenBottomLeft.x || pos.x > GameManager.screenTopRight.x || pos.z < GameManager.screenBottomLeft.z || pos.z > GameManager.screenTopRight.z) {
Destroy(bullet);
}
}
}