[TASK] Spawn collectable ducks on the map when in range
This commit is contained in:
150
Assets/MagicArsenal/Effects/Scripts/MagicBeamScript.cs
Normal file
150
Assets/MagicArsenal/Effects/Scripts/MagicBeamScript.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MagicBeamScript : MonoBehaviour {
|
||||
|
||||
[Header("Prefabs")]
|
||||
public GameObject[] beamLineRendererPrefab;
|
||||
public GameObject[] beamStartPrefab;
|
||||
public GameObject[] beamEndPrefab;
|
||||
|
||||
private int currentBeam = 0;
|
||||
|
||||
private GameObject beamStart;
|
||||
private GameObject beamEnd;
|
||||
private GameObject beam;
|
||||
private LineRenderer line;
|
||||
|
||||
[Header("Adjustable Variables")]
|
||||
public float beamEndOffset = 1f; //How far from the raycast hit point the end effect is positioned
|
||||
public float textureScrollSpeed = 8f; //How fast the texture scrolls along the beam
|
||||
public float textureLengthScale = 3; //Length of the beam texture
|
||||
|
||||
[Header("Put Sliders here (Optional)")]
|
||||
public Slider endOffSetSlider; //Use UpdateEndOffset function on slider
|
||||
public Slider scrollSpeedSlider; //Use UpdateScrollSpeed function on slider
|
||||
|
||||
[Header("Put UI Text object here to show beam name")]
|
||||
public Text textBeamName;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
if (textBeamName)
|
||||
textBeamName.text = beamLineRendererPrefab[currentBeam].name;
|
||||
if (endOffSetSlider)
|
||||
endOffSetSlider.value = beamEndOffset;
|
||||
if (scrollSpeedSlider)
|
||||
scrollSpeedSlider.value = textureScrollSpeed;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
Application.Quit();
|
||||
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
beamStart = Instantiate(beamStartPrefab[currentBeam], new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
beamEnd = Instantiate(beamEndPrefab[currentBeam], new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
beam = Instantiate(beamLineRendererPrefab[currentBeam], new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
line = beam.GetComponent<LineRenderer>();
|
||||
}
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
Destroy(beamStart);
|
||||
Destroy(beamEnd);
|
||||
Destroy(beam);
|
||||
}
|
||||
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray.origin, ray.direction, out hit))
|
||||
{
|
||||
Vector3 tdir = hit.point - transform.position;
|
||||
ShootBeamInDir(transform.position, tdir);
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.RightArrow)) //4 next if commands are just hotkeys for cycling beams
|
||||
{
|
||||
nextBeam();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.D))
|
||||
{
|
||||
nextBeam();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.A))
|
||||
{
|
||||
previousBeam();
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
{
|
||||
previousBeam();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void nextBeam() // Next beam
|
||||
{
|
||||
if (currentBeam < beamLineRendererPrefab.Length - 1)
|
||||
currentBeam++;
|
||||
else
|
||||
currentBeam = 0;
|
||||
|
||||
if (textBeamName)
|
||||
textBeamName.text = beamLineRendererPrefab[currentBeam].name;
|
||||
}
|
||||
|
||||
public void previousBeam() // Previous beam
|
||||
{
|
||||
if (currentBeam > - 0)
|
||||
currentBeam--;
|
||||
else
|
||||
currentBeam = beamLineRendererPrefab.Length - 1;
|
||||
|
||||
if (textBeamName)
|
||||
textBeamName.text = beamLineRendererPrefab[currentBeam].name;
|
||||
}
|
||||
|
||||
|
||||
public void UpdateEndOffset()
|
||||
{
|
||||
beamEndOffset = endOffSetSlider.value;
|
||||
}
|
||||
|
||||
public void UpdateScrollSpeed()
|
||||
{
|
||||
textureScrollSpeed = scrollSpeedSlider.value;
|
||||
}
|
||||
|
||||
void ShootBeamInDir(Vector3 start, Vector3 dir)
|
||||
{
|
||||
line.positionCount = 2;
|
||||
line.SetPosition(0, start);
|
||||
beamStart.transform.position = start;
|
||||
|
||||
Vector3 end = Vector3.zero;
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(start, dir, out hit))
|
||||
end = hit.point - (dir.normalized * beamEndOffset);
|
||||
else
|
||||
end = transform.position + (dir * 100);
|
||||
|
||||
beamEnd.transform.position = end;
|
||||
line.SetPosition(1, end);
|
||||
|
||||
beamStart.transform.LookAt(beamEnd.transform.position);
|
||||
beamEnd.transform.LookAt(beamStart.transform.position);
|
||||
|
||||
float distance = Vector3.Distance(start, end);
|
||||
line.sharedMaterial.mainTextureScale = new Vector2(distance / textureLengthScale, 1);
|
||||
line.sharedMaterial.mainTextureOffset -= new Vector2(Time.deltaTime * textureScrollSpeed, 0);
|
||||
}
|
||||
}
|
||||
12
Assets/MagicArsenal/Effects/Scripts/MagicBeamScript.cs.meta
Normal file
12
Assets/MagicArsenal/Effects/Scripts/MagicBeamScript.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ede43347e5e422d4692b421d77e89d7c
|
||||
timeCreated: 1475013530
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
38
Assets/MagicArsenal/Effects/Scripts/MagicLightFade.cs
Normal file
38
Assets/MagicArsenal/Effects/Scripts/MagicLightFade.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace MagicArsenal
|
||||
{
|
||||
public class MagicLightFade : MonoBehaviour
|
||||
{
|
||||
[Header("Seconds to dim the light")]
|
||||
public float life = 0.2f;
|
||||
public bool killAfterLife = true;
|
||||
|
||||
private Light li;
|
||||
private float initIntensity;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
if (gameObject.GetComponent<Light>())
|
||||
{
|
||||
li = gameObject.GetComponent<Light>();
|
||||
initIntensity = li.intensity;
|
||||
}
|
||||
else
|
||||
print("No light object found on " + gameObject.name);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (gameObject.GetComponent<Light>())
|
||||
{
|
||||
li.intensity -= initIntensity * (Time.deltaTime / life);
|
||||
if (killAfterLife && li.intensity <= 0)
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/MagicArsenal/Effects/Scripts/MagicLightFade.cs.meta
Normal file
12
Assets/MagicArsenal/Effects/Scripts/MagicLightFade.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67649a15b062c3a48b8ed3994d3c6e17
|
||||
timeCreated: 1493910049
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
61
Assets/MagicArsenal/Effects/Scripts/MagicLightFlicker.cs
Normal file
61
Assets/MagicArsenal/Effects/Scripts/MagicLightFlicker.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class MagicLightFlicker : MonoBehaviour
|
||||
{
|
||||
// Properties
|
||||
public string waveFunction = "sin"; // possible values: sin, tri(angle), sqr(square), saw(tooth), inv(verted sawtooth), noise (random)
|
||||
public float startValue = 0.0f; // start
|
||||
public float amplitude = 1.0f; // amplitude of the wave
|
||||
public float phase = 0.0f; // start point inside on wave cycle
|
||||
public float frequency = 0.5f; // cycle frequency per second
|
||||
|
||||
// Keep a copy of the original color
|
||||
private Color originalColor;
|
||||
|
||||
// Store the original color
|
||||
void Start (){
|
||||
originalColor = GetComponent<Light>().color;
|
||||
}
|
||||
|
||||
void Update (){
|
||||
Light light = GetComponent<Light>();
|
||||
light.color = originalColor * (EvalWave());
|
||||
}
|
||||
|
||||
float EvalWave (){
|
||||
float x = (Time.time + phase)*frequency;
|
||||
float y;
|
||||
|
||||
x = x - Mathf.Floor(x); // normalized value (0..1)
|
||||
|
||||
if (waveFunction=="sin") {
|
||||
y = Mathf.Sin(x*2*Mathf.PI);
|
||||
}
|
||||
else if (waveFunction=="tri") {
|
||||
if (x < 0.5f)
|
||||
y = 4.0f * x - 1.0f;
|
||||
else
|
||||
y = -4.0f * x + 3.0f;
|
||||
}
|
||||
else if (waveFunction=="sqr") {
|
||||
if (x < 0.5f)
|
||||
y = 1.0f;
|
||||
else
|
||||
y = -1.0f;
|
||||
}
|
||||
else if (waveFunction=="saw") {
|
||||
y = x;
|
||||
}
|
||||
else if (waveFunction=="inv") {
|
||||
y = 1.0f - x;
|
||||
}
|
||||
else if (waveFunction=="noise") {
|
||||
y = 1 - (Random.value*2);
|
||||
}
|
||||
else {
|
||||
y = 1.0f;
|
||||
}
|
||||
return (y*amplitude)+startValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ac49698f7a3feb408dd537ff46e2d07
|
||||
timeCreated: 1509114642
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/MagicArsenal/Effects/Scripts/MagicRotation.cs
Normal file
30
Assets/MagicArsenal/Effects/Scripts/MagicRotation.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace MagicArsenal
|
||||
{
|
||||
public class MagicRotation : MonoBehaviour
|
||||
{
|
||||
|
||||
[Header("Rotate axises by degrees per second")]
|
||||
public Vector3 rotateVector = Vector3.zero;
|
||||
|
||||
public enum spaceEnum { Local, World };
|
||||
public spaceEnum rotateSpace;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (rotateSpace == spaceEnum.Local)
|
||||
transform.Rotate(rotateVector * Time.deltaTime);
|
||||
if (rotateSpace == spaceEnum.World)
|
||||
transform.Rotate(rotateVector * Time.deltaTime, Space.World);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/MagicArsenal/Effects/Scripts/MagicRotation.cs.meta
Normal file
12
Assets/MagicArsenal/Effects/Scripts/MagicRotation.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a84c9fd6072e17c46b93dd9cf28a0904
|
||||
timeCreated: 1493910128
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user