Esempio n. 1
0
    private void Update()
    {
        switch (Input.inputString)
        {
        case "1":
            weapow = "bomb";
            break;

        case "2":
            weapow = "laser";
            break;
        }

        Debug.Log(weapow);

        Vector3 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
        Vector3 mouseDirection = Input.mousePosition - screenPosition;

        mouseDirection.z = 0.0f;

        var rotation = Quaternion.FromToRotation(startingDirection, mouseDirection);

        transform.localRotation = rotation;

        if (weapow == "bomb")
        {
            laser.SetActive(false);
            if (Input.GetMouseButtonDown(0))
            {
                mexe.Shakes(0.1f, 0.2f);

                Vector2 direction = ((Vector2)mouseDirection).normalized;
                Vector3 position  = transform.position + (Vector3)direction * instantiateOffset;

                var bullet = Instantiate(bulletPrefab.gameObject, position, Quaternion.identity).GetComponent <Bullet> ();
                bullet.impulse = direction * shootImpulse;
            }
        }
        if (weapow == "laser")
        {
            if (Input.GetMouseButton(0))
            {
                mexe.Shakes(0.5f, 0.1f);
                laserSoundSpawn();
                laser.SetActive(true);
            }
            if (Input.GetMouseButtonUp(0))
            {
                laser.SetActive(false);
            }
        }
    }