[TASK] Working on duck-catching minigame
This commit is contained in:
38
Assets/Polygon Arsenal/Scripts/PolygonLightFade.cs
Normal file
38
Assets/Polygon Arsenal/Scripts/PolygonLightFade.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace PolygonArsenal
|
||||
{
|
||||
public class PolygonLightFade : 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/Polygon Arsenal/Scripts/PolygonLightFade.cs.meta
Normal file
12
Assets/Polygon Arsenal/Scripts/PolygonLightFade.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52b907da54153884b95b31e930d046d2
|
||||
timeCreated: 1509044237
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
61
Assets/Polygon Arsenal/Scripts/PolygonLightFlicker.cs
Normal file
61
Assets/Polygon Arsenal/Scripts/PolygonLightFlicker.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class PolygonLightFlicker : 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;
|
||||
}
|
||||
}
|
||||
12
Assets/Polygon Arsenal/Scripts/PolygonLightFlicker.cs.meta
Normal file
12
Assets/Polygon Arsenal/Scripts/PolygonLightFlicker.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e700f8e20de2fdf4ab1bf79546b95202
|
||||
timeCreated: 1509044237
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/Polygon Arsenal/Scripts/PolygonRotation.cs
Normal file
30
Assets/Polygon Arsenal/Scripts/PolygonRotation.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace PolygonArsenal
|
||||
{
|
||||
public class PolygonRotation : 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/Polygon Arsenal/Scripts/PolygonRotation.cs.meta
Normal file
12
Assets/Polygon Arsenal/Scripts/PolygonRotation.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf86d4d543b2a3440b8b3ceb1db164c5
|
||||
timeCreated: 1509044237
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
45
Assets/Polygon Arsenal/Scripts/PolygonSoundSpawn.cs
Normal file
45
Assets/Polygon Arsenal/Scripts/PolygonSoundSpawn.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace PolygonArsenal
|
||||
{
|
||||
public class PolygonSoundSpawn : MonoBehaviour
|
||||
{
|
||||
|
||||
public GameObject prefabSound;
|
||||
|
||||
public bool destroyWhenDone = true;
|
||||
public bool soundPrefabIsChild = false;
|
||||
[Range(0.01f, 10f)]
|
||||
public float pitchRandomMultiplier = 1f;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
//Spawn the sound object
|
||||
GameObject m_Sound = Instantiate(prefabSound, transform.position, Quaternion.identity);
|
||||
AudioSource m_Source = m_Sound.GetComponent<AudioSource>();
|
||||
|
||||
//Attach object to parent if true
|
||||
if (soundPrefabIsChild)
|
||||
m_Sound.transform.SetParent(transform);
|
||||
|
||||
//Multiply pitch
|
||||
if (pitchRandomMultiplier != 1)
|
||||
{
|
||||
if (Random.value < .5)
|
||||
m_Source.pitch *= Random.Range(1 / pitchRandomMultiplier, 1);
|
||||
else
|
||||
m_Source.pitch *= Random.Range(1, pitchRandomMultiplier);
|
||||
}
|
||||
|
||||
//Set lifespan if true
|
||||
if (destroyWhenDone)
|
||||
{
|
||||
float life = m_Source.clip.length / m_Source.pitch;
|
||||
Destroy(m_Sound, life);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Polygon Arsenal/Scripts/PolygonSoundSpawn.cs.meta
Normal file
12
Assets/Polygon Arsenal/Scripts/PolygonSoundSpawn.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5aa5c1e37409a9344a344c0468db383d
|
||||
timeCreated: 1514648980
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user