You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Networking.Client;
  5. public class FloatingOnWater : MonoBehaviour
  6. {
  7. bool characterInWater = false;
  8. public ConnectedClients clientData;
  9. private List<string> Names;
  10. public GameObject lilypad;
  11. private void Start()
  12. {
  13. for(int i = 0; i < clientData.AllClients.Count; i++)
  14. {
  15. Names.Add(clientData.AllClients[i].characterAnimal + "(Clone)");
  16. }
  17. }
  18. void OnTriggerEnter(Collider other)
  19. {
  20. for(int i = 0; i < Names.Count; i++)
  21. {
  22. if (other.gameObject.name == Names[i])
  23. {
  24. characterInWater = true;
  25. }
  26. }
  27. }
  28. IEnumerator FloatSinkCoroutine(Vector3 endPosition)
  29. {
  30. float elapsedTime = 0;
  31. Vector3 startPosition = lilypad.transform.position;
  32. float time = 0.8f;
  33. while (elapsedTime < time)
  34. {
  35. transform.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
  36. yield return new WaitForEndOfFrame();
  37. elapsedTime += Time.deltaTime;
  38. }
  39. lilypad.transform.position = endPosition;
  40. }
  41. public void Animate()
  42. {
  43. StartCoroutine(FloatSinkCoroutine(new Vector3(0, 1, 0)));
  44. }
  45. public void returnToPosition()
  46. {
  47. StartCoroutine(FloatSinkCoroutine(new Vector3(0, 0, 0)));
  48. }
  49. }