-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
Assets/BattlemageVR/Resources/Scripts/DespawnAtLocation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class DespawnAtLocation : MonoBehaviour | ||
{ | ||
public Vector3 TargetLocation = new Vector3(0, 0, 0); | ||
|
||
// Update is called once per frame | ||
void Update () { | ||
if((transform.position - TargetLocation).magnitude < .0001f) | ||
{ | ||
Destroy(gameObject); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
Assets/BattlemageVR/Resources/Scripts/EnemyProjectileSpawnZone.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class EnemyProjectileSpawnZone : MonoBehaviour | ||
{ | ||
public float SpawnRateInSeconds = 1; | ||
|
||
private float _lastSpawnTime = 0; | ||
|
||
// Update is called once per frame | ||
void Update () { | ||
if(Time.time - _lastSpawnTime > SpawnRateInSeconds) | ||
{ | ||
_lastSpawnTime = Time.time; | ||
SpawnRandomProjectile(); | ||
} | ||
} | ||
|
||
private void SpawnRandomProjectile() | ||
{ | ||
var t = transform; | ||
var extent = t.localScale / 2; | ||
var topForwardRight = t.position + t.up * extent.y + t.right * extent.x + t.forward * extent.z; | ||
var bottomBackLeft = t.position - t.up * extent.y - t.right * extent.x - t.forward * extent.z; | ||
var randPosition = new Vector3( | ||
RandRange(topForwardRight.x, bottomBackLeft.x), | ||
RandRange(topForwardRight.y, bottomBackLeft.y), | ||
RandRange(topForwardRight.z, bottomBackLeft.z)); | ||
|
||
var projectile = CreateProjectile(randPosition, new Vector3(0, 1, 0)); | ||
projectile.transform.SetParent(transform, true); | ||
} | ||
|
||
private static GameObject CreateProjectile(Vector3 position, Vector3 target) | ||
{ | ||
var projectile = Instantiate(PrefabFactory.RedFireballPrefab); | ||
projectile.transform.position = position; | ||
|
||
var moveScript = projectile.AddComponent<MoveToLocation>(); | ||
moveScript.Speed = 1f; | ||
moveScript.TargetPosition = target; | ||
|
||
var despawnScript = projectile.AddComponent<DespawnAtLocation>(); | ||
despawnScript.TargetLocation = target; | ||
|
||
return projectile; | ||
} | ||
|
||
private static float RandRange(float a, float b) | ||
{ | ||
if(a < b) | ||
return Random.Range(a, b); | ||
return Random.Range(b, a); | ||
} | ||
|
||
// Draw the bounds of the spawn zone in edit mode | ||
void OnDrawGizmos() | ||
{ | ||
Gizmos.color = Color.yellow; | ||
Gizmos.DrawWireCube(transform.position, transform.localScale); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class MoveToLocation : MonoBehaviour { | ||
public Vector3 TargetPosition = new Vector2(); | ||
public float Speed = 1; | ||
|
||
// Update is called once per frame | ||
void Update () { | ||
var moveAmount = Speed * Time.deltaTime; | ||
var direction = TargetPosition - transform.position; | ||
|
||
if(moveAmount > direction.magnitude) | ||
{ | ||
moveAmount = direction.magnitude; | ||
} | ||
|
||
transform.position += moveAmount * direction.normalized; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public static class PrefabFactory | ||
{ | ||
public static readonly GameObject RedFireballPrefab = (GameObject)Resources.Load("Prefabs/RedFireball"); | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.