Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Enemy : MonoBehaviour
  6. {
  7. public float velocidadY;
  8. public float maxY;
  9. private float posY;
  10. private float direction;
  11.  
  12. public Transform ballPosition;
  13.  
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. if(ballPosition.position.y>transform.position.y){
  18. direction = 1.0f;
  19. }else{
  20. direction = -1.0f;
  21. }
  22.  
  23. posY = transform.position.y + direction*velocidadY*Time.deltaTime;
  24.  
  25. if(posY>maxY){
  26. posY = maxY;
  27. }else if(posY<-maxY){
  28. posY = -maxY;
  29. }
  30.  
  31. transform.position = new Vector3(transform.position.x, posY, transform.position.z);
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement