Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class barrelLerp : MonoBehaviour
  6. {
  7. Vector3 startPos;
  8. public Transform endPos;
  9. public float t;
  10. public AnimationCurve barrelAnim;
  11. public bool shot;
  12.  
  13. void Start()
  14. {
  15. shot = false;
  16. }
  17.  
  18.  
  19. void Update()
  20. {
  21. startPos = transform.position;
  22.  
  23. if (Input.GetMouseButtonDown(0) && !shot)
  24. {
  25. shot = true;
  26.  
  27. }
  28.  
  29. if(shot)
  30. {
  31. t += Time.deltaTime;
  32.  
  33.  
  34. if (t>=1)
  35. {
  36. t = 0;
  37. shot = false;
  38.  
  39. }
  40.  
  41. LerpMovement();
  42. }
  43. }
  44.  
  45. void LerpMovement()
  46. {
  47.  
  48. transform.position = Vector3.Lerp(startPos, endPos.position,barrelAnim.Evaluate(t));
  49. print("Animazione completata");
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement