void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Enemy" && player.is_attacking) { AnimalObject enemy = other.GetComponent <AnimalObject>(); enemy._hp--; Vector3 hit_pos = new Vector3(other.transform.position.x + 50, other.transform.position.y, other.transform.position.z); other.transform.position = Vector3.Lerp(other.transform.position, hit_pos, Time.deltaTime); //(System).Random rand = new (System).Random(); int number = Random.Range(0, 3); if (enemy._hp <= 0) { if (number == 0 || number == 1) { GameObject GiftBox; Vector3 pos_animal = other.transform.position; GiftBox = Instantiate(Resources.Load("Prefabs/gift_box"), pos_animal, Quaternion.identity) as GameObject; GiftBox.name = "GiftBox"; // name을 변경 GiftBox.transform.parent = GameObject.Find(other.transform.root.name).transform; } Destroy(other.gameObject); } player.is_attacking = false; Debug.Log("E " + enemy._hp); } }
private void CreateAnimal(AnimalInfo info) { GameObject animalObject = SimplePool.Spawn(AnimalPrefab.gameObject); animalObject.transform.SetParent(AnimalsParent); animalObject.transform.localPosition = new Vector3(); animalObject.transform.localScale = new Vector3(1, 1, 1); AnimalObject animal = animalObject.GetComponent <AnimalObject>(); animal.SetSprite(info.Portrait); animal.Controller = this; DescriptionText.text = info.Description; CurrentAnimal = animal; }
public void StartMovingAuto(AnimalObject animal, float speed, float target) { StopMovingAuto(); _animal = animal; _target = target; _startPos = transform.localPosition.x; if (_startPos == _target) { _animal.OnMovingFinished(); return; } _speed = speed / (Mathf.Abs(_startPos - _target)); _startTime = Time.time; MovingCoroutine = StartCoroutine(MovingProcess()); }
public async Task AddAnimal(AnimalObject animal) { var name = animal.Name; if (name is null) { return; } Type type = Type.GetType($"Zoo.Animals.{animal.Type}"); Gender gender = (Gender)int.Parse(animal.Gender); _animalService.AddAnimal((Animal)Activator.CreateInstance(type, name, gender)); await Clients.All.Refresh(); }
public void OnAnimalEndDrag(AnimalObject animal) { if (animal != CurrentAnimal) { return; } Vector2 animalScreenPoint = RectTransformUtility.WorldToScreenPoint(null, animal.transform.position); Vector2 leftPoint = RectTransformUtility.WorldToScreenPoint(null, BoundaryPointLeft.position); Vector2 rightPoint = RectTransformUtility.WorldToScreenPoint(null, BoundaryPointRight.position); if (leftPoint.x > animalScreenPoint.x) { MoveToLeft(); } else if (rightPoint.x < animalScreenPoint.x) { MoveToRight(); } else { MoveToCenter(); } }
void Start() { animal = this.transform.root.GetComponent <AnimalObject>(); }
public void DestroyAnimal(AnimalObject animal) { SimplePool.Despawn(animal.gameObject); }