private void Update() { if (startMove) { Vector3 pos = Vector3.MoveTowards(transform.position, target.position, speed * Time.deltaTime); GetComponent <Rigidbody>().MovePosition(pos); Color color = material.color; color.a -= 0.15f; material.color = color; } //Debug.Log("transform.position" + transform.position); //Debug.Log("target.position" + target.position); if (Mathf.Approximately(transform.position.y, target.position.y)) { Debug.Log("in the if: "); OnCoinPicked?.Invoke(false); //var terrainDisplayer = GameObject.FindObjectOfType(typeof(TerrainDisplayer)) as TerrainDisplayer; startMove = false; if (terrainDisplayer != null && terrainDisplayer.PrefabManager != null && terrainDisplayer.PrefabManager.Pool != null) { material.color = initialColor; terrainDisplayer.PrefabManager.Pool.Remove(this.gameObject); //terrainDisplayer.PrefabManager.Pool.Remove(this.gameObject); } } //Debug.Log("startMove: " + startMove); }
public void InvokeOnCoinPicked(object a_sender) { if (OnCoinPicked != null) { OnCoinPicked.Invoke(a_sender); } }
void OnTriggerEnter(Collider item) { terrainDisplayer = GameObject.FindObjectOfType(typeof(TerrainDisplayer)) as TerrainDisplayer; //Assume only one terrain displayer at a time if (item.name == "surfer_Sphere") { if (terrainDisplayer != null && terrainDisplayer.PrefabManager != null && terrainDisplayer.PrefabManager.Pool != null) { audioSource.PlayOneShot(bottleSound); Scoring.Instance.ScorePickup(); OnCoinPicked?.Invoke(true); startMove = true; //terrainDisplayer.PrefabManager.Pool.Remove(this.gameObject); } } }