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.

50 lines
1.2 KiB

4 years ago
4 years ago
4 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ExplosionTest : MonoBehaviour
  5. {
  6. [SerializeField]
  7. private float Force = 1;
  8. [SerializeField]
  9. private float speed;
  10. [SerializeField]
  11. private Vector3 direction;
  12. Vector3 start;
  13. float ratio;
  14. private void Start()
  15. {
  16. start = transform.position;
  17. }
  18. private void Update()
  19. {
  20. ratio = Mathf.Sin(Time.time * speed);
  21. transform.position = Vector3.Lerp(start, start + direction, (ratio+1)/2);
  22. }
  23. private void OnDrawGizmosSelected()
  24. {
  25. if (Application.isPlaying)
  26. Gizmos.DrawWireSphere(start + direction, 10);
  27. else
  28. Gizmos.DrawWireSphere(transform.position + direction, 10);
  29. }
  30. private void OnTriggerStay(Collider other)
  31. {
  32. var horse = other.GetComponent<PlayerController>();
  33. if (horse != null)
  34. {
  35. horse.AddForce((direction.normalized * Mathf.Cos(Time.time *speed) + Vector3.up) * Force);
  36. Debug.DrawRay(horse.transform.position, (direction.normalized + Vector3.up) * Mathf.Cos(Time.time * speed) * Force, Color.red, 0.5f);
  37. }
  38. }
  39. }