Added enemies initial prefabs

This commit is contained in:
Trianta
2024-03-13 17:46:25 -05:00
parent 65730bed50
commit b2d02e7133
21 changed files with 2566 additions and 7 deletions
+62
View File
@@ -0,0 +1,62 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Keeps a GameObject on screen.
/// Note that this ONLY works for an orthographic Main Camera at [ 0, 0, 0 ].
/// </summary>
public class BoundsCheck : MonoBehaviour
{
[Header("Set in Inspector")]
public float radius = 1f;
[Header("Set Dynamically")]
public float camWidth;
public float camHeight;
void Awake() {
camHeight = Camera.main.orthographicSize;
camWidth = camHeight * Camera.main.aspect;
}
void LateUpdate () {
Vector3 pos = transform.position;
if (pos.x > camWidth - radius) {
pos.x = camWidth - radius;
}
if (pos.x < -camWidth + radius) {
pos.x = -camWidth + radius;
}
if (pos.y > camHeight - radius) {
pos.y = camHeight - radius;
}
if (pos.y < -camHeight + radius) {
pos.y = -camHeight + radius;
}
transform.position = pos;
}
// Draw the bounds in the Scene pane using OnDrawGizmos()
void OnDrawGizmos () {
if (!Application.isPlaying) return;
Vector3 boundSize = new Vector3(camWidth* 2, camHeight* 2, 0.1f);
Gizmos.DrawWireCube(Vector3.zero, boundSize);
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a2b7c79b712fe5c9ca22495cdf2f32b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+48
View File
@@ -0,0 +1,48 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hero : MonoBehaviour
{
static public Hero S;
[Header("Set in Inspector")]
// These fields control the movement of the ship
public float speed = 30;
public float rollMult = -45;
public float pitchMult = 30;
[Header("Set Dynamically")]
public float shieldLevel = 1;
void Awake() {
if (S == null) {
S = this;
} else {
Debug.LogError("Hero.Awake() - Attempted to assign second Hero.S!");
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
// Pull in information from the Input class
float xAxis = Input.GetAxis("Horizontal");
float yAxis = Input.GetAxis("Vertical");
// Change transform.position based on the axes
Vector3 pos = transform.position;
pos.x += xAxis * speed * Time.deltaTime;
pos.y += yAxis * speed * Time.deltaTime;
transform.position = pos;
// Rotate the ship to make it feel more dynamic
transform.rotation = Quaternion.Euler(yAxis*pitchMult,xAxis*rollMult,0);
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 80c6957dc77f8444db5712d0b089cbc3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+36
View File
@@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shield : MonoBehaviour
{
[Header("Set in Inspector")]
public float rotationsPerSecond = 0.1f;
[Header("Set Dynamically")]
public int levelShown = 0;
// This non-public variable will not appear in the Inspector
Material mat;
// Start is called before the first frame update
void Start()
{
mat = GetComponent<Renderer>().material;
}
// Update is called once per frame
void Update()
{
// Read the current shield level from the Hero Singleton
int currLevel = Mathf.FloorToInt(Hero.S.shieldLevel);
// If this is different from levelShown...
if (levelShown != currLevel) {
levelShown = currLevel;
// Adjust the texture offset to show different shield level
mat.mainTextureOffset = new Vector2( 0.2f*levelShown, 0);
}
// Rotate the shield a bit every frame in a time-based way
float rZ = -(rotationsPerSecond*Time.time*3600) % 360f;
transform.rotation = Quaternion.Euler( 0, 0, rZ );
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 140a959058dd2f121ba93544cbe8a05d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: