You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RatAttack2D/Assets/Scripts/Frog_Tung.cs

43 lines
1.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Frog_Tung : MonoBehaviour
{
public Rigidbody2D rb;
[System.NonSerialized]public int setDmg;
private int Damage;
[System.NonSerialized]public string OwnTag;
private bool ret;
private void Start()
{
Damage = setDmg;
rb.AddForce((Vector2)(Quaternion.Euler(0,0,rb.rotation) * Vector2.right) * 50, ForceMode2D.Impulse);
}
private void OnTriggerEnter2D(Collider2D other)
{
if(other.CompareTag(OwnTag))
{
if(ret)
{
other.GetComponent<Enemy_Frog>().canMove = true;
other.GetComponent<Enemy_Frog>().wait = 5;
other.GetComponent<Animator>().SetTrigger("exit");
GameObject.Destroy(this.gameObject);
}
return;
}
if(other.CompareTag("Bullet") || ret)
{
return;
}
if(other.TryGetComponent<Health>(out Health health))
{
health.RemoveHP(Damage);
}
rb.velocity = new Vector2(0, 0);
rb.AddForce((Vector2)(Quaternion.Euler(0,0,rb.rotation) * Vector2.left) * 50, ForceMode2D.Impulse);
ret = true;
}
}