Hi
I’m still pretty new with C# (switching from unity script)
I have the following script in the scene, with a few collectibles that are placed in “collectibles” array in the inspector.
The script works, up to the point of the foreach - obviously I"m doing something wrong. I’m trying to destroy the collectible from the list when the player taps on it.
using UnityEngine;
using System.Collections;
public class TouchCollect : MonoBehaviour {
public GameObject[] collectibles;
private int _numberToCollect;
void Start(){
collectibles = GameObject.FindGameObjectsWithTag ("Collectible");
_numberToCollect = collectibles.Length;
Debug.Log ("Number to collect at start = " + _numberToCollect);
}
// Subscribe to events
void OnEnable(){
EasyTouch.On_TouchStart += On_TouchStart;
}
void OnDisable(){
UnsubscribeEvent();
}
void OnDestroy(){
UnsubscribeEvent();
}
void UnsubscribeEvent(){
EasyTouch.On_TouchStart -= On_TouchStart;
}
// Simple tap
private void On_TouchStart( Gesture gesture){
foreach (GameObject collected in collectibles)
// Verification that the action on the object
if (gesture.pickObject == collected/* RevealPickup.isShowing*/){
Destroy(collected);
_numberToCollect--;
Debug.Log ("Number left to collect = "+_numberToCollect);
}
}
}
Any direction would be appreciated.
Thanks