[TASK] Spawn collectable ducks on the map when in range
This commit is contained in:
60
Assets/MagicArsenal/Demo/Scripts/MagicButtonScript.cs
Normal file
60
Assets/MagicArsenal/Demo/Scripts/MagicButtonScript.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MagicArsenal
|
||||
{
|
||||
|
||||
public class MagicButtonScript : MonoBehaviour
|
||||
{
|
||||
public GameObject Button;
|
||||
Text MyButtonText;
|
||||
string projectileParticleName; // The variable to update the text component of the button
|
||||
|
||||
MagicFireProjectile effectScript; // A variable used to access the list of projectiles
|
||||
MagicProjectileScript projectileScript;
|
||||
|
||||
public float buttonsX;
|
||||
public float buttonsY;
|
||||
public float buttonsSizeX;
|
||||
public float buttonsSizeY;
|
||||
public float buttonsDistance;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
effectScript = GameObject.Find("MagicFireProjectile").GetComponent<MagicFireProjectile>();
|
||||
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
|
||||
{
|
||||
// Access the currently selected projectile's 'ProjectileScript'
|
||||
projectileScript = effectScript.projectiles[effectScript.currentProjectile].GetComponent<MagicProjectileScript>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/MagicArsenal/Demo/Scripts/MagicButtonScript.cs.meta
Normal file
12
Assets/MagicArsenal/Demo/Scripts/MagicButtonScript.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 253ef25e6b5a90e43ab2e2f4bccdf47e
|
||||
timeCreated: 1493903207
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
74
Assets/MagicArsenal/Demo/Scripts/MagicDragMouseOrbit.cs
Normal file
74
Assets/MagicArsenal/Demo/Scripts/MagicDragMouseOrbit.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace MagicArsenal
|
||||
{
|
||||
|
||||
public class MagicDragMouseOrbit : 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/MagicArsenal/Demo/Scripts/MagicDragMouseOrbit.cs.meta
Normal file
12
Assets/MagicArsenal/Demo/Scripts/MagicDragMouseOrbit.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad7865037d6f63e42bc9119855cfc7f5
|
||||
timeCreated: 1493903221
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
86
Assets/MagicArsenal/Demo/Scripts/MagicFireProjectile.cs
Normal file
86
Assets/MagicArsenal/Demo/Scripts/MagicFireProjectile.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using System.Collections;
|
||||
|
||||
namespace MagicArsenal
|
||||
{
|
||||
public class MagicFireProjectile : MonoBehaviour
|
||||
{
|
||||
RaycastHit hit;
|
||||
public GameObject[] projectiles;
|
||||
public Transform spawnPosition;
|
||||
[HideInInspector]
|
||||
public int currentProjectile = 0;
|
||||
public float speed = 1000;
|
||||
|
||||
// MyGUI _GUI;
|
||||
MagicButtonScript selectedProjectileButton;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
selectedProjectileButton = GameObject.Find("Button").GetComponent<MagicButtonScript>();
|
||||
}
|
||||
|
||||
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);
|
||||
projectile.GetComponent<MagicProjectileScript>().impactNormal = hit.normal;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/MagicArsenal/Demo/Scripts/MagicFireProjectile.cs.meta
Normal file
12
Assets/MagicArsenal/Demo/Scripts/MagicFireProjectile.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3312d60fb8e28004e9946a80a5627cbf
|
||||
timeCreated: 1493903241
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
73
Assets/MagicArsenal/Demo/Scripts/MagicLoadSceneOnClick.cs
Normal file
73
Assets/MagicArsenal/Demo/Scripts/MagicLoadSceneOnClick.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class MagicLoadSceneOnClick : MonoBehaviour
|
||||
{
|
||||
public void LoadSceneProjectiles()
|
||||
{
|
||||
SceneManager.LoadScene("magic_projectiles");
|
||||
}
|
||||
public void LoadSceneSprays()
|
||||
{
|
||||
SceneManager.LoadScene("magic_sprays");
|
||||
}
|
||||
public void LoadSceneAura()
|
||||
{
|
||||
SceneManager.LoadScene("magic_aura");
|
||||
}
|
||||
public void LoadSceneModular()
|
||||
{
|
||||
SceneManager.LoadScene("magic_modular");
|
||||
}
|
||||
public void LoadSceneShields2()
|
||||
{
|
||||
SceneManager.LoadScene("magic_domes");
|
||||
}
|
||||
public void LoadSceneShields()
|
||||
{
|
||||
SceneManager.LoadScene("magic_shields");
|
||||
}
|
||||
public void LoadSceneSphereBlast()
|
||||
{
|
||||
SceneManager.LoadScene("magic_sphereblast");
|
||||
}
|
||||
public void LoadSceneEnchant()
|
||||
{
|
||||
SceneManager.LoadScene("magic_enchant");
|
||||
}
|
||||
public void LoadSceneSlash()
|
||||
{
|
||||
SceneManager.LoadScene("magic_slash");
|
||||
}
|
||||
public void LoadSceneCharge()
|
||||
{
|
||||
SceneManager.LoadScene("magic_charge");
|
||||
}
|
||||
public void LoadSceneCleave()
|
||||
{
|
||||
SceneManager.LoadScene("magic_cleave");
|
||||
}
|
||||
public void LoadSceneAura2()
|
||||
{
|
||||
SceneManager.LoadScene("magic_aura2");
|
||||
}
|
||||
public void LoadSceneWalls()
|
||||
{
|
||||
SceneManager.LoadScene("magic_walls");
|
||||
}
|
||||
public void LoadSceneBeams()
|
||||
{
|
||||
SceneManager.LoadScene("magic_beams");
|
||||
}
|
||||
public void LoadSceneMeshGlow()
|
||||
{
|
||||
SceneManager.LoadScene("magic_meshglow");
|
||||
}
|
||||
public void LoadScenePillarBlast()
|
||||
{
|
||||
SceneManager.LoadScene("magic_pillarblast");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9cee07dde16fe347a792e0790381210
|
||||
timeCreated: 1493903197
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/MagicArsenal/Demo/Scripts/MagicLoopScript.cs
Normal file
33
Assets/MagicArsenal/Demo/Scripts/MagicLoopScript.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace MagicArsenal {
|
||||
|
||||
public class MagicLoopScript : 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);
|
||||
|
||||
yield return new WaitForSeconds(loopTimeLimit);
|
||||
|
||||
Destroy (effectPlayer);
|
||||
PlayEffect();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/MagicArsenal/Demo/Scripts/MagicLoopScript.cs.meta
Normal file
12
Assets/MagicArsenal/Demo/Scripts/MagicLoopScript.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2c2487f3502aea429a3a0935c7c992f
|
||||
timeCreated: 1493903086
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
65
Assets/MagicArsenal/Demo/Scripts/MagicProjectileScript.cs
Normal file
65
Assets/MagicArsenal/Demo/Scripts/MagicProjectileScript.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class MagicProjectileScript : MonoBehaviour
|
||||
{
|
||||
public GameObject impactParticle;
|
||||
public GameObject projectileParticle;
|
||||
public GameObject muzzleParticle;
|
||||
public GameObject[] trailParticles;
|
||||
[HideInInspector]
|
||||
public Vector3 impactNormal; //Used to rotate impactparticle.
|
||||
|
||||
private bool hasCollided = false;
|
||||
|
||||
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 OnCollisionEnter(Collision hit)
|
||||
{
|
||||
if (!hasCollided)
|
||||
{
|
||||
hasCollided = true;
|
||||
//transform.DetachChildren();
|
||||
impactParticle = Instantiate(impactParticle, transform.position, Quaternion.FromToRotation(Vector3.up, impactNormal)) as GameObject;
|
||||
//Debug.DrawRay(hit.contacts[0].point, hit.contacts[0].normal * 1, Color.yellow);
|
||||
|
||||
if (hit.gameObject.tag == "Destructible") // Projectile will destroy objects tagged as Destructible
|
||||
{
|
||||
Destroy(hit.gameObject);
|
||||
}
|
||||
|
||||
|
||||
//yield WaitForSeconds (0.05);
|
||||
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);
|
||||
//projectileParticle.Stop();
|
||||
|
||||
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"))
|
||||
continue;
|
||||
|
||||
trail.transform.SetParent(null);
|
||||
Destroy(trail.gameObject, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c49efb715a1395643b158a8846980bcd
|
||||
timeCreated: 1493903252
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user