// Use this for initialization void Start() { _timeRun = 3.0f; _state = LFAnimalState.walk; _targetPosition = transform.position; _anim = gameObject.GetComponent <Animator> (); UpdatePath(); }
void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "tPlayerAttack") { _state = LFAnimalState.run; _timeRun = runTime; UpdatePath(); /*GameObject blood = Instantiate(bloodPrefab, _targetPosition, Quaternion.identity); * blood.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); * StartCoroutine (GameOver ());*/ //other.gameObject.transform.parent.gameObject.GetComponent<LFPlayer> ().Hit (damage); } }
// Update is called once per frame void Update() { if (_targetPosition != null && !EnemyOnTargetNode()) { transform.position = Vector3.MoveTowards(transform.position, _targetPosition, speedScaleFactor * speed * Time.deltaTime); } else { switch (_state) { case LFAnimalState.run: _moveSpeed = speed * speedScaleFactor; break; default: _moveSpeed = speed; break; } if ((_path.Count - 1) > _pathStepIndex) { _pathStepIndex += 1; _targetNode = _path[_pathStepIndex]; _targetPosition = new Vector3(_targetNode.WorldPosition.x, _targetNode.WorldPosition.y, transform.position.z); } else { UpdatePath(); } } UpdateSprite(); if (_state == LFAnimalState.run && _timeRun <= 0) { _state = LFAnimalState.walk; _timeRun = runTime; } else if (_state == LFAnimalState.run && _timeRun > 0) { _timeRun -= Time.deltaTime; } }