From d54c5334f8511bc77f7d2394e6a35113305a46b6 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 20 Apr 2020 21:31:30 +0200 Subject: [PATCH] Add some scripts --- Assets/Scripts/Generic/FollowMouse.cs | 37 +++++++++++++++++++ .../FollowMouse.cs.meta | 0 Assets/Scripts/Microgame_Earth/FollowMouse.cs | 27 -------------- Assets/Scripts/Microgame_IT.meta | 8 ++++ Assets/Scripts/Microgame_IT/EatIfOver.cs | 20 ++++++++++ Assets/Scripts/Microgame_IT/EatIfOver.cs.meta | 11 ++++++ Assets/Sound/Microgame_YourShip.meta | 8 ++++ .../Sound/Microgame_YourShip/splash.wav.meta | 22 +++++++++++ 8 files changed, 106 insertions(+), 27 deletions(-) create mode 100644 Assets/Scripts/Generic/FollowMouse.cs rename Assets/Scripts/{Microgame_Earth => Generic}/FollowMouse.cs.meta (100%) delete mode 100644 Assets/Scripts/Microgame_Earth/FollowMouse.cs create mode 100644 Assets/Scripts/Microgame_IT.meta create mode 100644 Assets/Scripts/Microgame_IT/EatIfOver.cs create mode 100644 Assets/Scripts/Microgame_IT/EatIfOver.cs.meta create mode 100644 Assets/Sound/Microgame_YourShip.meta create mode 100644 Assets/Sound/Microgame_YourShip/splash.wav.meta diff --git a/Assets/Scripts/Generic/FollowMouse.cs b/Assets/Scripts/Generic/FollowMouse.cs new file mode 100644 index 0000000..e3093af --- /dev/null +++ b/Assets/Scripts/Generic/FollowMouse.cs @@ -0,0 +1,37 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public enum FollowMouseOptions { + ALWAYS, + ONLY_WHEN_HOLDING_LMB +} + +[RequireComponent(typeof(Rigidbody2D))] +public class FollowMouse : MonoBehaviour +{ + public Vector2 min; + public Vector2 max; + public FollowMouseOptions options = FollowMouseOptions.ALWAYS; + + private new Rigidbody2D rigidbody2D; + + void Awake() { + rigidbody2D = GetComponent(); + } + + void Start() { + if(options == FollowMouseOptions.ALWAYS) { + Vector3 screenPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); + transform.position = new Vector3(Mathf.Clamp(screenPoint.x, min.x, max.x), Mathf.Clamp(screenPoint.y, min.y, max.y), transform.position.z); + } + } + + void FixedUpdate() + { + if(options == FollowMouseOptions.ALWAYS) { + Vector3 screenPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); + transform.position = new Vector3(Mathf.Clamp(screenPoint.x, min.x, max.x), Mathf.Clamp(screenPoint.y, min.y, max.y), transform.position.z); + } + } +} diff --git a/Assets/Scripts/Microgame_Earth/FollowMouse.cs.meta b/Assets/Scripts/Generic/FollowMouse.cs.meta similarity index 100% rename from Assets/Scripts/Microgame_Earth/FollowMouse.cs.meta rename to Assets/Scripts/Generic/FollowMouse.cs.meta diff --git a/Assets/Scripts/Microgame_Earth/FollowMouse.cs b/Assets/Scripts/Microgame_Earth/FollowMouse.cs deleted file mode 100644 index 22b9ba0..0000000 --- a/Assets/Scripts/Microgame_Earth/FollowMouse.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -[RequireComponent(typeof(Rigidbody2D))] -public class FollowMouse : MonoBehaviour -{ - public Vector2 min; - public Vector2 max; - - private new Rigidbody2D rigidbody2D; - - void Awake() { - rigidbody2D = GetComponent(); - } - - void Start() { - Vector3 screenPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); - transform.position = new Vector3(Mathf.Clamp(screenPoint.x, min.x, max.x), Mathf.Clamp(screenPoint.y, min.y, max.y), transform.position.z); - } - - void FixedUpdate() - { - Vector3 screenPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); - rigidbody2D.MovePosition(new Vector3(Mathf.Clamp(screenPoint.x, min.x, max.x), Mathf.Clamp(screenPoint.y, min.y, max.y), transform.position.z)); - } -} diff --git a/Assets/Scripts/Microgame_IT.meta b/Assets/Scripts/Microgame_IT.meta new file mode 100644 index 0000000..e4e0496 --- /dev/null +++ b/Assets/Scripts/Microgame_IT.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d32d78df161e754499c868a56c75e21f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Microgame_IT/EatIfOver.cs b/Assets/Scripts/Microgame_IT/EatIfOver.cs new file mode 100644 index 0000000..e9c0e70 --- /dev/null +++ b/Assets/Scripts/Microgame_IT/EatIfOver.cs @@ -0,0 +1,20 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(AudioSource))] +public class EatIfOver : MonoBehaviour +{ + private AudioSource audioSource; + + void Awake() { + audioSource = GetComponent(); + } + + void OnTriggerStay2D(Collider2D other) { + if(other.tag == "Enemy" && !Input.GetMouseButton(0)) { + audioSource.Play(); + Destroy(other.gameObject); + } + } +} diff --git a/Assets/Scripts/Microgame_IT/EatIfOver.cs.meta b/Assets/Scripts/Microgame_IT/EatIfOver.cs.meta new file mode 100644 index 0000000..c612a71 --- /dev/null +++ b/Assets/Scripts/Microgame_IT/EatIfOver.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c3817aab5e68ab643932247cddde9cc9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Sound/Microgame_YourShip.meta b/Assets/Sound/Microgame_YourShip.meta new file mode 100644 index 0000000..358629c --- /dev/null +++ b/Assets/Sound/Microgame_YourShip.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: af8e88ce9eaceb949a6f5735b8178565 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Sound/Microgame_YourShip/splash.wav.meta b/Assets/Sound/Microgame_YourShip/splash.wav.meta new file mode 100644 index 0000000..7534f10 --- /dev/null +++ b/Assets/Sound/Microgame_YourShip/splash.wav.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: 3862d528d79cd124880c6b991817a00e +AudioImporter: + externalObjects: {} + serializedVersion: 6 + defaultSettings: + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + preloadAudioData: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: