Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.Events;
- [System.Serializable]
- public class MyVectorEvent: UnityEvent<Vector3> { }
- public class Player : MonoBehaviour
- {
- public float moveSpeed = 3;
- // reveal an event in the inspector called "OnPositionChanged"
- public MyVectorEvent OnPositionChanged;
- void Update()
- {
- // Get input
- if (Input.GetKeyDown(KeyCode.Space))
- {
- // move forward
- transform.Translate(transform.forward * moveSpeed * Time.deltaTime);
- // send out an event broadcast to all listeners with the new transform position
- OnPositionChanged.Invoke(transform.position)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment