using System.Collections; using System.Collections.Generic; using UnityEngine; using Networking.Client; public class FloatingOnWater : MonoBehaviour { bool characterInWater = false; public ConnectedClients clientData; private List Names; public GameObject lilypad; private void Start() { for(int i = 0; i < clientData.AllClients.Count; i++) { Names.Add(clientData.AllClients[i].characterAnimal + "(Clone)"); } } void OnTriggerEnter(Collider other) { for(int i = 0; i < Names.Count; i++) { if (other.gameObject.name == Names[i]) { characterInWater = true; } } } IEnumerator FloatSinkCoroutine(Vector3 endPosition) { float elapsedTime = 0; Vector3 startPosition = lilypad.transform.position; float time = 0.8f; while (elapsedTime < time) { transform.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time)); yield return new WaitForEndOfFrame(); elapsedTime += Time.deltaTime; } lilypad.transform.position = endPosition; } public void Animate() { StartCoroutine(FloatSinkCoroutine(new Vector3(0, 1, 0))); } public void returnToPosition() { StartCoroutine(FloatSinkCoroutine(new Vector3(0, 0, 0))); } }