Kenkaster001

collectible

Sep 10th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Collectible : MonoBehaviour
  6. {
  7. float speed = 10;
  8. public GameObject player;
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12.  
  13. }
  14.  
  15. // Update is called once per frame
  16. void Update()
  17. {
  18. Vector3 rotation = new Vector3(15,30,45) * Time.deltaTime * speed;
  19. transform.Rotate(rotation);
  20.  
  21.  
  22.  
  23. Vector3 vector = transform.position - player.transform.position;
  24.  
  25. float magnitude = vector.magnitude;
  26.  
  27. if (magnitude > 3)
  28. {
  29. GetComponent<MeshRenderer>().material.color = Color.red;
  30. }
  31. else
  32. {
  33. GetComponent<MeshRenderer>().material.color = Color.blue;
  34. }
  35. }
  36. }
Add Comment
Please, Sign In to add comment