Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EnemyTouch : MonoBehaviour
- {
- public int currentScore;
- public TextMeshProUGUI textScore;
- Collider2D col;
- public float minX;
- public float maxX;
- public float minY;
- public float maxY;
- Vector2 targetPosition;
- public float baseSpeed = 0.7f;
- public float speedBoost = 5.0f;
- bool boosting;
- void Start()
- {
- col = GetComponent<Collider2D>();
- targetPosition = GetRandomPosition();
- }
- // Update is called once per frame
- void Update()
- {
- textScore.text = currentScore.ToString();
- EnemyMovement();
- }
- void EnemyMovement()
- {
- /* if ((Vector2)transform.position != targetPosition && EnemyTouchAndScore()==true )
- {
- StartCoroutine(BoostSpeedCo());
- }*/
- //Si al menos se toca una vez la screen
- if (Input.touchCount > 0)
- {
- Touch touch = Input.GetTouch(0);
- Vector2 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
- if (touch.phase == TouchPhase.Began)
- {
- Collider2D touchedCollider = Physics2D.OverlapPoint(touchPosition);
- if (col == touchedCollider)
- {
- currentScore += 1;
- // return true;
- }
- }
- }
- if ((Vector2)transform.position != targetPosition)
- {
- transform.position = Vector2.MoveTowards(transform.position, targetPosition, baseSpeed * Time.deltaTime);
- }
- else
- {
- targetPosition = GetRandomPosition();
- }
- }
- Vector2 GetRandomPosition()
- {
- float randomX = Random.Range(minX, maxX);
- float randomY = Random.Range(minY, maxY);
- return new Vector2(randomX, randomY);
- }
- IEnumerator BoostSpeedCo()
- {
- transform.position = Vector2.MoveTowards(transform.position, targetPosition, speedBoost * Time.deltaTime);
- Debug.Log("boost");
- yield return new WaitForSeconds(3.0f);
- // transform.position = Vector2.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement