// Update is called once per frame void Update() { _time += Time.deltaTime; if (_time >= interpolationPeriod) { _time = _time - interpolationPeriod; _targetPosition = RandomPatrol.GetRandomPos(); } Debug.DrawLine(_targetPosition, transform.position); if ((Vector2)transform.position != _targetPosition) { _speed = Mathf.Lerp(minspeed, maxspeed, GetDifficultyPercent()); transform.position = Vector2.MoveTowards( transform.position, _targetPosition, _speed * Time.deltaTime ); } else { _targetPosition = RandomPatrol.GetRandomPos(); } }
public void SetRandomPos() { Vector2 newPos = RandomPatrol.GetRandomPos(); bool isTooClose = true; while (isTooClose) { newPos = RandomPatrol.GetRandomPos(); isTooClose = false; foreach (var badBall in GameObject.FindGameObjectsWithTag("BadBalls")) { if (Vector2.Distance(newPos, badBall.transform.position) < cleanRange) { isTooClose = true; break; } } foreach (var badBall in GameObject.FindGameObjectsWithTag("Balls")) { if (Vector2.Distance(newPos, badBall.transform.position) < cleanRange) { isTooClose = true; break; } } } transform.position = newPos; }
// Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>(); col = GetComponent <Collider2D>(); madSprite.SetActive(false); rp = GetComponent <RandomPatrol>(); source = GetComponent <AudioSource>(); }
// Start is called before the first frame update void Start() { _time = 0; _audioSource = GetComponent <AudioSource>(); _targetPosition = RandomPatrol.GetRandomPos(); }
// Use this for initialization void Start() { sr = gameObject.GetComponent <SpriteRenderer>(); rp = GetComponent <RandomPatrol>(); source = GetComponent <AudioSource>(); }