1
Fork 0
mirror of https://github.com/Steffo99/keep-everything-alive.git synced 2024-11-22 01:14:19 +00:00

Add some scripts

This commit is contained in:
Steffo 2020-04-20 21:31:30 +02:00
parent f8cc1c04cd
commit d54c5334f8
8 changed files with 106 additions and 27 deletions

View 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);
}
}
}

View file

@ -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));
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d32d78df161e754499c868a56c75e21f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c3817aab5e68ab643932247cddde9cc9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: af8e88ce9eaceb949a6f5735b8178565
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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: