eastbayeff

Untitled

Mar 26th, 2022
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3.  
  4. [System.Serializable]
  5. public class MyVectorEvent: UnityEvent<Vector3> { }
  6.  
  7. public class Player : MonoBehaviour
  8. {
  9.     public float moveSpeed = 3;
  10.  
  11.     // reveal an event in the inspector called "OnPositionChanged"
  12.     public MyVectorEvent OnPositionChanged;
  13.    
  14.     void Update()
  15.     {  
  16.         // Get input
  17.         if (Input.GetKeyDown(KeyCode.Space))
  18.         {
  19.             // move forward
  20.             transform.Translate(transform.forward * moveSpeed * Time.deltaTime);
  21.  
  22.             // send out an event broadcast to all listeners with the new transform position
  23.             OnPositionChanged.Invoke(transform.position)
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment