mirror of
https://github.com/Steffo99/keep-everything-alive.git
synced 2024-11-21 17:04:20 +00:00
Add some scripts
This commit is contained in:
parent
f8cc1c04cd
commit
d54c5334f8
8 changed files with 106 additions and 27 deletions
37
Assets/Scripts/Generic/FollowMouse.cs
Normal file
37
Assets/Scripts/Generic/FollowMouse.cs
Normal file
|
@ -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<Rigidbody2D>();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Rigidbody2D>();
|
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
8
Assets/Scripts/Microgame_IT.meta
Normal file
8
Assets/Scripts/Microgame_IT.meta
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d32d78df161e754499c868a56c75e21f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
20
Assets/Scripts/Microgame_IT/EatIfOver.cs
Normal file
20
Assets/Scripts/Microgame_IT/EatIfOver.cs
Normal file
|
@ -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<AudioSource>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTriggerStay2D(Collider2D other) {
|
||||||
|
if(other.tag == "Enemy" && !Input.GetMouseButton(0)) {
|
||||||
|
audioSource.Play();
|
||||||
|
Destroy(other.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Microgame_IT/EatIfOver.cs.meta
Normal file
11
Assets/Scripts/Microgame_IT/EatIfOver.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c3817aab5e68ab643932247cddde9cc9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
8
Assets/Sound/Microgame_YourShip.meta
Normal file
8
Assets/Sound/Microgame_YourShip.meta
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: af8e88ce9eaceb949a6f5735b8178565
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
22
Assets/Sound/Microgame_YourShip/splash.wav.meta
Normal file
22
Assets/Sound/Microgame_YourShip/splash.wav.meta
Normal file
|
@ -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:
|
Loading…
Reference in a new issue