public ProjectileEntity(ProjectilePhysics physics, Vector2 direction)
 {
     this.Name      = this.GetType().Name;
     this.physics   = physics;
     this.direction = direction;
     Rotate(Mathf.Pi + direction.Angle());
     Connect("body_entered", this, nameof(OnBodyEntered));
     AddCollider();
     AddSprite("res://assets/magic_projectile.png");
 }
示例#2
0
    void OnTriggerEnter2D(Collider2D otherCollider)
    {
        // Is this a shot?
        ProjectilePhysics shot = otherCollider.gameObject.GetComponent <ProjectilePhysics>();

        if (shot != null)
        {
            Damage(shot.damage);

            // Destroy the shot
            Destroy(shot.gameObject); // Remember to always target the game object, otherwise you will just remove the script
        }
    }
示例#3
0
 public override void ViewDidLoad()
 {
     base.ViewDidLoad();
     _physics = new ProjectilePhysics(100f, 1, 30);
     this.RefreshView();
 }