// Update is called once per frame protected override void Update() { base.Update(); if (this.GetItem().state == Item.State.ON_GROUND && this.state == State.WANDER) { Monster minMonster = null; float minDistance = float.PositiveInfinity; foreach (Monster monster in FindObjectsOfType <Monster>()) { if (monster.Initialized() && monster != this && monster.state != State.DEAD && monster.state != State.DYING) { float distance = ((Vector2)monster.transform.position - (Vector2)this.transform.position).magnitude; if (distance < minDistance) { minDistance = distance; minMonster = monster; } } } if (minMonster != null) { Type monsterType = minMonster.GetType(); if (!this.copycatProcess.ContainsKey(monsterType)) { this.copycatProcess.Add(monsterType, 0f); } this.copycatProcess[monsterType] += Time.deltaTime; if (this.copycatProcess[monsterType] > Copycat.COPYCAT_TIME) { GameObject prefab = PrefabManager.GetMonsterPrefab(monsterType); Monster monster = Instantiate(prefab, this.transform.position, Quaternion.identity).GetComponent <Monster>(); monster.SetCopycat(true); monster.orbs = this.orbs; Destroy(this.gameObject); } if (UnityEngine.Random.value > 1 - Time.deltaTime / 0.5f) { GameObject particleObj = Instantiate(PrefabManager.COPYCAT_PARTICLE_PREFAB, minMonster.transform.position, Quaternion.identity); Particle particle = particleObj.GetComponent <Particle>(); particle.target = this.transform.position; } } } }