Grabbing food

This commit is contained in:
Pascal Serrarens 2025-02-17 16:02:29 +01:00
parent 6551c653c3
commit 923cb317af
2 changed files with 11 additions and 13 deletions

View File

@ -1,7 +1,8 @@
namespace Passer.Control.Core { namespace Passer.Control.Core {
public class TouchSensor : Thing { public class TouchSensor : Thing {
public Thing touchedThing = null; //public Thing touchedThing = null;
public bool touchedSomething = false;
public TouchSensor(bool invokeEvent = true) : base(invokeEvent) { public TouchSensor(bool invokeEvent = true) : base(invokeEvent) {
} }

View File

@ -1,5 +1,4 @@
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
using System.Collections;
using UnityEngine; using UnityEngine;
namespace Passer.Control.Unity { namespace Passer.Control.Unity {
@ -14,13 +13,6 @@ namespace Passer.Control.Unity {
if (core == null) if (core == null)
SetCoreThing(new Core.TouchSensor()); SetCoreThing(new Core.TouchSensor());
//StartCoroutine(MeasureDistance());
}
bool update = false;
protected override void Update() {
base.Update();
this.update= false;
} }
public static TouchSensor Create(Core.TouchSensor core) { public static TouchSensor Create(Core.TouchSensor core) {
@ -30,7 +22,7 @@ namespace Passer.Control.Unity {
TouchSensor component = gameObj.AddComponent<TouchSensor>(); TouchSensor component = gameObj.AddComponent<TouchSensor>();
Rigidbody rb = gameObj.AddComponent<Rigidbody>(); Rigidbody rb = gameObj.AddComponent<Rigidbody>();
rb.isKinematic = true; rb.isKinematic = true;
SphereCollider collider = gameObj.AddComponent<SphereCollider>(); SphereCollider collider = gameObj.AddComponent<SphereCollider>();
collider.radius = 0.01F; collider.radius = 0.01F;
collider.isTrigger = true; collider.isTrigger = true;
@ -46,11 +38,16 @@ namespace Passer.Control.Unity {
} }
private void OnTriggerEnter(Collider other) { private void OnTriggerEnter(Collider other) {
Debug.Log("Touch!"); if (other.isTrigger)
this.coreSensor.touchedThing = other.transform.GetComponentInParent<Thing>().core; return;
this.coreSensor.touchedSomething = true;
} }
private void OnTriggerExit(Collider other) { private void OnTriggerExit(Collider other) {
this.coreSensor.touchedThing = null; if (other.isTrigger)
return;
this.coreSensor.touchedSomething = false;
} }
} }
} }