コード例 #1
0
    void Fire()         // for player
    {
        cam = Camera.main;
        // Get mouse position in game world
        Vector3 mouseWorldPoint = Camera.main.ScreenToWorldPoint((Vector2)Input.mousePosition);

        // get distance for raycast d = sqrt(pow((x2 - x1), 2), pow((y2 - y1), 2))
        float x1 = transform.position.x;
        float y1 = transform.position.y;
        float x2 = mouseWorldPoint.x;
        float y2 = mouseWorldPoint.y;

        float distance = Mathf.Sqrt((Mathf.Pow((x2 - x1), 2) + Mathf.Pow((y2 - y1), 2)));


        Vector3 click = mouseWorldPoint - transform.position;

        Debug.DrawLine(transform.position, mouseWorldPoint, Color.red);
        // cast from player pos to mouse pos
        RaycastHit2D hit = Physics2D.Raycast(transform.position, click, distance, enemyLayerMask);

        if (hit.collider)
        {
            hit.collider.gameObject.GetComponent <EnemyManager>().hSystem.Damage(20);
            ultBar.AddUlt(ultChargeAmt);
        }
    }
コード例 #2
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag("Enemy"))
     {
         ultBar.AddUlt(50);
     }
 }
コード例 #3
0
    private void Update()
    {
        x = Input.GetAxis("Horizontal");
        y = Input.GetAxis("Vertical");

        if (x != 0 || y != 0)
        {
            lastMove = new Vector2(x, y);
        }

        if (Input.GetButtonDown("Fire1"))
        {
            // play anim
            anim.Play("strike");

            // spawn hitbox
            var center = transform.XandY() + lastMove.normalized * range;
            var hits   = Physics2D.OverlapCircleAll(center, radius, enemyLayer);
            foreach (var col in hits)
            {
                if (col.gameObject.CompareTag("Enemy"))
                {
                    col.gameObject.GetComponent <EnemyManager>().hSystem.Damage(20);
                    ultBar.AddUlt(ultChargeAmt);
                    hitboxColor = Color.green;
                }
            }
        }
    }
コード例 #4
0
    private void Update()
    {
        // Debug Only
        if (Input.GetKeyDown(KeyCode.F))
        {
            ultBar.AddUlt(100);
        }

        if (ultReady && Input.GetKeyDown(KeyCode.Mouse2))
        {
            ultReady = false;
            UseUlt();
        }
    }