[TASK] Working on duck-catching minigame

This commit is contained in:
2019-08-27 01:48:20 +02:00
parent a507a4e70e
commit 9057c295da
3403 changed files with 8231793 additions and 40 deletions

View File

@@ -0,0 +1,154 @@
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
namespace PolygonArsenal
{
public class PolygonBeamScript : 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);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e948078d20c9c95428422d457dc24914
timeCreated: 1528645636
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,59 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
namespace PolygonArsenal
{
public class PolygonButtonScript : MonoBehaviour
{
public GameObject Button;
Text MyButtonText;
string projectileParticleName; // The variable to update the text component of the button
PolygonFireProjectile effectScript; // A variable used to access the list of projectiles
PolygonProjectileScript projectileScript;
public float buttonsX;
public float buttonsY;
public float buttonsSizeX;
public float buttonsSizeY;
public float buttonsDistance;
void Start()
{
effectScript = GameObject.Find("PolygonFireProjectile").GetComponent<PolygonFireProjectile>(); // The FireProjectile script needs to be on a gameobject called FireProjectile, or else it won't be found
getProjectileNames();
MyButtonText = Button.transform.Find("Text").GetComponent<Text>();
MyButtonText.text = projectileParticleName;
}
void Update()
{
MyButtonText.text = projectileParticleName;
// print(projectileParticleName);
}
public void getProjectileNames() // Find and diplay the name of the currently selected projectile
{
projectileScript = effectScript.projectiles[effectScript.currentProjectile].GetComponent<PolygonProjectileScript>();// Access the currently selected projectile's 'ProjectileScript'
projectileParticleName = projectileScript.projectileParticle.name; // Assign the name of the currently selected projectile to projectileParticleName
}
public bool overButton() // This function will return either true or false
{
Rect button1 = new Rect(buttonsX, buttonsY, buttonsSizeX, buttonsSizeY);
Rect button2 = new Rect(buttonsX + buttonsDistance, buttonsY, buttonsSizeX, buttonsSizeY);
if (button1.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)) ||
button2.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))
{
return true;
}
else
return false;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0a14325ec4c536541b2a754406153fe7
timeCreated: 1508516918
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,85 @@
using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections;
namespace PolygonArsenal
{
public class PolygonFireProjectile : MonoBehaviour
{
RaycastHit hit;
public GameObject[] projectiles;
public Transform spawnPosition;
[HideInInspector]
public int currentProjectile = 0;
public float speed = 1000;
// MyGUI _GUI;
PolygonButtonScript selectedProjectileButton;
void Start()
{
selectedProjectileButton = GameObject.Find("Button").GetComponent<PolygonButtonScript>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.RightArrow))
{
nextEffect();
}
if (Input.GetKeyDown(KeyCode.D))
{
nextEffect();
}
if (Input.GetKeyDown(KeyCode.A))
{
previousEffect();
}
else if (Input.GetKeyDown(KeyCode.LeftArrow))
{
previousEffect();
}
if (Input.GetKeyDown(KeyCode.Mouse0))
{
if (!EventSystem.current.IsPointerOverGameObject())
{
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100f))
{
GameObject projectile = Instantiate(projectiles[currentProjectile], spawnPosition.position, Quaternion.identity) as GameObject;
projectile.transform.LookAt(hit.point);
projectile.GetComponent<Rigidbody>().AddForce(projectile.transform.forward * speed);
}
}
}
Debug.DrawRay(Camera.main.ScreenPointToRay(Input.mousePosition).origin, Camera.main.ScreenPointToRay(Input.mousePosition).direction * 100, Color.yellow);
}
public void nextEffect()
{
if (currentProjectile < projectiles.Length - 1)
currentProjectile++;
else
currentProjectile = 0;
selectedProjectileButton.getProjectileNames();
}
public void previousEffect()
{
if (currentProjectile > 0)
currentProjectile--;
else
currentProjectile = projectiles.Length - 1;
selectedProjectileButton.getProjectileNames();
}
public void AdjustSpeed(float newSpeed)
{
speed = newSpeed;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 82096b18a42c3a2468c199a9bf5ee1c2
timeCreated: 1508516994
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
using UnityEngine;
using System.Collections;
namespace PolygonArsenal
{
public class PolygonLoopScript : MonoBehaviour
{
public GameObject chosenEffect;
public float loopTimeLimit = 2.0f;
void Start()
{
PlayEffect();
}
public void PlayEffect()
{
StartCoroutine("EffectLoop");
}
IEnumerator EffectLoop()
{
//GameObject effectPlayer = (GameObject)Instantiate(chosenEffect, transform.position, transform.rotation);
GameObject effectPlayer = (GameObject)Instantiate(chosenEffect);
effectPlayer.transform.position = transform.position;
//effectPlayer.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
yield return new WaitForSeconds(loopTimeLimit);
Destroy(effectPlayer);
PlayEffect();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 12eda49810402c344b42c34203ffdccc
timeCreated: 1508516972
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,70 @@
using UnityEngine;
using System.Collections;
[AddComponentMenu("Camera-Control/Mouse drag Orbit with zoom")]
public class PolygonOrbit : MonoBehaviour
{
public Transform target;
public float distance = 5.0f;
public float xSpeed = 120.0f;
public float ySpeed = 120.0f;
public float yMinLimit = -20f;
public float yMaxLimit = 80f;
public float distanceMin = .5f;
public float distanceMax = 15f;
public float smoothTime = 2f;
float rotationYAxis = 0.0f;
float rotationXAxis = 0.0f;
float velocityX = 0.0f;
float velocityY = 0.0f;
// Use this for initialization
void Start()
{
Vector3 angles = transform.eulerAngles;
rotationYAxis = angles.y;
rotationXAxis = angles.x;
// Make the rigid body not change rotation
if (GetComponent<Rigidbody>())
{
GetComponent<Rigidbody>().freezeRotation = true;
}
}
void LateUpdate()
{
if (target)
{
if (Input.GetMouseButton(1))
{
velocityX += xSpeed * Input.GetAxis("Mouse X") * distance * 0.02f;
velocityY += ySpeed * Input.GetAxis("Mouse Y") * 0.02f;
}
rotationYAxis += velocityX;
rotationXAxis -= velocityY;
rotationXAxis = ClampAngle(rotationXAxis, yMinLimit, yMaxLimit);
//Quaternion fromRotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, 0);
Quaternion toRotation = Quaternion.Euler(rotationXAxis, rotationYAxis, 0);
Quaternion rotation = toRotation;
distance = Mathf.Clamp(distance - Input.GetAxis("Mouse ScrollWheel") * 5, distanceMin, distanceMax);
RaycastHit hit;
if (Physics.Linecast(target.position, transform.position, out hit))
{
distance -= hit.distance;
}
Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
Vector3 position = rotation * negDistance + target.position;
transform.rotation = rotation;
transform.position = position;
velocityX = Mathf.Lerp(velocityX, 0, Time.deltaTime * smoothTime);
velocityY = Mathf.Lerp(velocityY, 0, Time.deltaTime * smoothTime);
}
}
public static float ClampAngle(float angle, float min, float max)
{
if (angle < -360F)
angle += 360F;
if (angle > 360F)
angle -= 360F;
return Mathf.Clamp(angle, min, max);
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 225f1b6c1a43124458cb013772dc26aa
timeCreated: 1508516906
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,122 @@
using UnityEngine;
using System.Collections;
namespace PolygonArsenal
{
public class PolygonProjectileScript : MonoBehaviour
{
public GameObject impactParticle;
public GameObject projectileParticle;
public GameObject muzzleParticle;
public GameObject[] trailParticles;
[Header("Adjust if not using Sphere Collider")]
public float colliderRadius = 1f;
[Range(0f, 1f)]
public float collideOffset = 0.15f;
void Start()
{
projectileParticle = Instantiate(projectileParticle, transform.position, transform.rotation) as GameObject;
projectileParticle.transform.parent = transform;
if (muzzleParticle)
{
muzzleParticle = Instantiate(muzzleParticle, transform.position, transform.rotation) as GameObject;
Destroy(muzzleParticle, 1.5f); // Lifetime of muzzle effect.
}
}
void FixedUpdate()
{
RaycastHit hit;
float rad;
if (transform.GetComponent<SphereCollider>())
rad = transform.GetComponent<SphereCollider>().radius;
else
rad = colliderRadius;
Vector3 dir = transform.GetComponent<Rigidbody>().velocity;
if (transform.GetComponent<Rigidbody>().useGravity)
dir += Physics.gravity * Time.deltaTime;
dir = dir.normalized;
float dist = transform.GetComponent<Rigidbody>().velocity.magnitude * Time.deltaTime;
if (Physics.SphereCast(transform.position, rad, dir, out hit, dist))
{
transform.position = hit.point + (hit.normal * collideOffset);
GameObject impactP = Instantiate(impactParticle, transform.position, Quaternion.FromToRotation(Vector3.up, hit.normal)) as GameObject;
if (hit.transform.tag == "Destructible") // Projectile will destroy objects tagged as Destructible
{
Destroy(hit.transform.gameObject);
}
foreach (GameObject trail in trailParticles)
{
GameObject curTrail = transform.Find(projectileParticle.name + "/" + trail.name).gameObject;
curTrail.transform.parent = null;
Destroy(curTrail, 3f);
}
Destroy(projectileParticle, 3f);
Destroy(impactP, 3.5f);
Destroy(gameObject);
ParticleSystem[] trails = GetComponentsInChildren<ParticleSystem>();
//Component at [0] is that of the parent i.e. this object (if there is any)
for (int i = 1; i < trails.Length; i++)
{
ParticleSystem trail = trails[i];
if (trail.gameObject.name.Contains("Trail"))
{
trail.transform.SetParent(null);
Destroy(trail.gameObject, 2f);
}
}
}
}
//private bool hasCollided = false;
/*void OnCollisionEnter(Collision hit)
{
if (!hasCollided)
{
hasCollided = true;
impactParticle = Instantiate(impactParticle, transform.position, Quaternion.FromToRotation(Vector3.up, impactNormal)) as GameObject;
if (hit.gameObject.tag == "Destructible") // Projectile will destroy objects tagged as Destructible
{
Destroy(hit.gameObject);
}
foreach (GameObject trail in trailParticles)
{
GameObject curTrail = transform.Find(projectileParticle.name + "/" + trail.name).gameObject;
curTrail.transform.parent = null;
Destroy(curTrail, 3f);
}
Destroy(projectileParticle, 3f);
Destroy(impactParticle, 5f);
Destroy(gameObject);
ParticleSystem[] trails = GetComponentsInChildren<ParticleSystem>();
//Component at [0] is that of the parent i.e. this object (if there is any)
for (int i = 1; i < trails.Length; i++)
{
ParticleSystem trail = trails[i];
if (trail.gameObject.name.Contains("Trail"))
{
trail.transform.SetParent(null);
Destroy(trail.gameObject, 2f);
}
}
}
}*/
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c736e84d8f869d245b3d1dba36061db9
timeCreated: 1508516945
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,167 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.Events;
namespace PolygonArsenal
{
public class PolygonSceneSelect : MonoBehaviour
{
public bool GUIHide = false;
public bool GUIHide2 = false;
public bool GUIHide3 = false;
public void LoadSceneDemoMissiles()
{
SceneManager.LoadScene("PolygonDemoMissiles");
}
public void LoadSceneDemoBeams()
{
SceneManager.LoadScene("PolygonDemoBeams");
}
public void LoadSceneDemo01()
{
SceneManager.LoadScene("PolygonDemo01");
}
public void LoadSceneDemo02()
{
SceneManager.LoadScene("PolygonDemo02");
}
public void LoadSceneDemo03()
{
SceneManager.LoadScene("PolygonDemo03");
}
public void LoadSceneDemo04()
{
SceneManager.LoadScene("PolygonDemo04");
}
public void LoadSceneDemo05()
{
SceneManager.LoadScene("PolygonDemo05");
}
public void LoadSceneDemo06()
{
SceneManager.LoadScene("PolygonDemo06");
}
public void LoadSceneDemo07()
{
SceneManager.LoadScene("PolygonDemo07");
}
public void LoadSceneDemo08()
{
SceneManager.LoadScene("PolygonDemo08");
}
public void LoadSceneDemo09()
{
SceneManager.LoadScene("PolygonDemo09");
}
public void LoadSceneDemo10()
{
SceneManager.LoadScene("PolygonDemo10");
}
public void LoadSceneDemo11()
{
SceneManager.LoadScene("PolygonDemo11");
}
public void LoadSceneDemo12()
{
SceneManager.LoadScene("PolygonDemo12");
}
public void LoadSceneDemo13()
{
SceneManager.LoadScene("PolygonDemo13");
}
public void LoadSceneDemo14()
{
SceneManager.LoadScene("PolygonDemo14");
}
public void LoadSceneDemo15()
{
SceneManager.LoadScene("PolygonDemo15");
}
public void LoadSceneDemo16()
{
SceneManager.LoadScene("PolygonDemo16");
}
public void LoadSceneDemo17()
{
SceneManager.LoadScene("PolygonDemo17");
}
public void LoadSceneDemo18()
{
SceneManager.LoadScene("PolygonDemo18");
}
public void LoadSceneDemo19()
{
SceneManager.LoadScene("PolygonDemo19");
}
public void LoadSceneDemo20()
{
SceneManager.LoadScene("PolygonDemo20");
}
public void LoadSceneDemo21()
{
SceneManager.LoadScene("PolygonDemo21");
}
public void LoadSceneDemo22()
{
SceneManager.LoadScene("PolygonDemo22");
}
public void LoadSceneDemo23()
{
SceneManager.LoadScene("PolygonDemo23");
}
void Update ()
{
if(Input.GetKeyDown(KeyCode.L))
{
GUIHide = !GUIHide;
if (GUIHide)
{
GameObject.Find("CanvasSceneSelect").GetComponent<Canvas> ().enabled = false;
}
else
{
GameObject.Find("CanvasSceneSelect").GetComponent<Canvas> ().enabled = true;
}
}
if(Input.GetKeyDown(KeyCode.J))
{
GUIHide2 = !GUIHide2;
if (GUIHide2)
{
GameObject.Find("CanvasMissiles").GetComponent<Canvas> ().enabled = false;
}
else
{
GameObject.Find("CanvasMissiles").GetComponent<Canvas> ().enabled = true;
}
}
if(Input.GetKeyDown(KeyCode.H))
{
GUIHide3 = !GUIHide3;
if (GUIHide3)
{
GameObject.Find("CanvasTips").GetComponent<Canvas> ().enabled = false;
}
else
{
GameObject.Find("CanvasTips").GetComponent<Canvas> ().enabled = true;
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 843947ef86e21b04597cfe2d21f2d819
timeCreated: 1508516959
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: