コード例 #1
0
ファイル: Ship.cs プロジェクト: VsIG-official/Study-Projects
    /// <summary>
    /// Update is called once per frame
    /// </summary>
    void Update()
    {
        // check for rotation input
        float rotationInput = Input.GetAxis("Rotate");

        if (rotationInput != 0)
        {
            // calculate rotation amount and apply rotation
            float rotationAmount = RotateDegreesPerSecond * Time.deltaTime;
            if (rotationInput < 0)
            {
                rotationAmount *= -1;
            }
            transform.Rotate(Vector3.forward, rotationAmount);

            // change thrust direction to match ship rotation
            float zRotation = transform.eulerAngles.z * Mathf.Deg2Rad;
            thrustDirection.x = Mathf.Cos(zRotation);
            thrustDirection.y = Mathf.Sin(zRotation);
        }

        // shoot as appropriate
        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            GameObject bullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
            Bullet     script = bullet.GetComponent <Bullet>();
            script.ApplyForce(thrustDirection);
            AudioManager.Play(AudioClipName.PlayerShot);
        }
    }
コード例 #2
0
ファイル: Player.cs プロジェクト: jamieeeeeeeee/badcodegame
    // Update is called once per frame
    void Update()
    {
        // Check on the left side of the screen
        if (transform.position.x <= -8f)
        {
            transform.position = new Vector3(-8f, transform.position.y, 0f);
        }
        // Check on the right side of the screen
        if (transform.position.x >= 8f)
        {
            transform.position = new Vector3(8f, transform.position.y, 0f);
        }

        // Fire a bullet
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Vector3 bulletPosition = transform.position;
            // Place the bullet above the player
            bulletPosition.y += GetComponent <CircleCollider2D>().radius;
            GameObject bullet = Instantiate(prefabBullet, bulletPosition, Quaternion.identity);
            Bullet     script = bullet.GetComponent <Bullet>();

            // Send it up
            script.ApplyForce(new Vector3(0, 1, 0));
        }
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        LocationInfo = gameObject.transform.position;
        rotation.z   = gameObject.transform.eulerAngles.z;
        float Head = rotation.z;

        Head = Head * Mathf.Deg2Rad;
        thrustDirection.x = -Mathf.Sin(Head);
        thrustDirection.y = Mathf.Cos(Head);

        if (Input.GetAxis("Axis Rotate") > 0)
        {
            transform.Rotate(Vector3.forward, rotationAmount);
        }
        if (Input.GetAxis("Axis Rotate") < 0)
        {
            transform.Rotate(Vector3.forward, -rotationAmount);
        }

        //shoot bullet
        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            GameObject Bullet = Instantiate(Resources.Load <GameObject>("PreFAps/bullet"), gameObject.transform.position, gameObject.transform.rotation) as GameObject;
            Bullet     script = Bullet.GetComponent <Bullet>();
            script.ApplyForce(thrustDirection);
            Bullet.GetComponent <AudioSource>().Play();
        }
    }
コード例 #4
0
    // Update is called once per frame
    void Update()
    {
        float rotation = Input.GetAxis("Rotate");

        if (rotation != 0f) // if we have rotation specified by the user
        {
            // get the amount of rotation amount
            float rotationAmountInDegrees = RotateDegreesPerSecond * Time.deltaTime;

            // if rotation direction is negative, change the amount accordingly
            if (rotation > 0)
            {
                rotationAmountInDegrees *= -1;
            }

            // apply the new rotation
            transform.Rotate(Vector3.forward, rotationAmountInDegrees);

            // update the thrustDirection to be along the new ship direction
            float currentZRotationInDegrees = transform.eulerAngles.z;
            float currentZRotationInRadians = currentZRotationInDegrees * Mathf.Deg2Rad;
            thrustDirection = new Vector2(Mathf.Cos(currentZRotationInRadians), Mathf.Sin(currentZRotationInRadians));
        }

        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            AudioManager.Play(AudioClipName.PlayerShot);

            Bullet bullet = Instantiate <Bullet>(prefabBullet, transform.position, Quaternion.identity);
            bullet.ApplyForce(thrustDirection);
        }
    }
コード例 #5
0
    void Update()
    {
        //For rotation Processing
        float rotationInput = Input.GetAxis("Rotate");

        if (rotationInput != 0)
        {
            float rotationAmount = RotationDegreePerSecond * Time.deltaTime;
            if (rotationInput < 0)
            {
                rotationAmount *= -1;
            }
            transform.Rotate(Vector3.forward, rotationAmount);
            Vector3 eulerAngle    = transform.eulerAngles;
            float   requiredAngle = eulerAngle.z;
            float   angle         = Mathf.Deg2Rad * requiredAngle;
            thrustDirection.x = -Mathf.Sin(angle);
            thrustDirection.y = Mathf.Cos(angle);
        }
        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            GameObject bullet = Instantiate <GameObject>(
                bulletPrefab, transform.position, Quaternion.identity);
            Bullet script = bullet.GetComponent <Bullet>();
            script.ApplyForce(thrustDirection);
            AudioManager.Play(AudioClipName.PlayerShot);
        }
    }
コード例 #6
0
ファイル: AIAiming.cs プロジェクト: nfonseca1/Tanks-Prototype
    public void Fire(float launchVelocity, Bullet bullet)
    {
        Bullet currentBullet = Instantiate(bullet, emitters[currentBarrel].position, emitters[currentBarrel].rotation);

        currentBullet.ApplyForce(launchVelocity);
        Destroy(currentBullet.gameObject, 10f);
        ApplyFireSettings();
    }
コード例 #7
0
ファイル: Ship.cs プロジェクト: kpagilla/Asteroids
    // Update is called once per frame
    void Update()
    {
        float rotationInput  = Input.GetAxis("Rotate");
        float rotationAmount = RotateDegreesPerSecond * Time.deltaTime;

        if (rotationInput < 0)
        {
            rotationAmount *= -1;

            float angle = transform.eulerAngles.z;

            thrustDirection.x = Mathf.Cos(Mathf.Deg2Rad * angle);
            thrustDirection.y = Mathf.Sin(Mathf.Deg2Rad * angle);

            transform.Rotate(Vector3.forward, rotationAmount);
        }
        else if (rotationInput > 0)
        {
            float angle = transform.eulerAngles.z;

            thrustDirection.x = Mathf.Cos(Mathf.Deg2Rad * angle);
            thrustDirection.y = Mathf.Sin(Mathf.Deg2Rad * angle);

            transform.Rotate(Vector3.forward, rotationAmount);
        }

        if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.LeftShift))
        {
            AudioManager.Play(AudioClipName.PlayerShot);

            Vector3 position = gameObject.transform.position;

            GameObject bullet = Instantiate(prefabBullet) as GameObject;

            float angle = transform.eulerAngles.z;

            Vector3 bulletPosition = transform.position;

            bulletPosition.x += Mathf.Cos(Mathf.Deg2Rad * angle) * 2;
            bulletPosition.y += Mathf.Sin(Mathf.Deg2Rad * angle) * 2;


            bullet.transform.position    = bulletPosition;
            bullet.transform.eulerAngles = transform.eulerAngles;

            Bullet component = bullet.GetComponent <Bullet>();
            component.ApplyForce(thrustDirection);
        }
    }
コード例 #8
0
ファイル: Turret.cs プロジェクト: nfonseca1/Tanks-Prototype
    private void Fire(Transform barrel, Transform emitter)
    {
        Bullet currentBullet = Instantiate(bullet, emitter.position, emitter.rotation);

        currentBullet.ApplyForce(launchVelocity);
        Destroy(currentBullet.gameObject, bulletLifetime);

        if (leftBarrelIsNext)
        {
            leftBarrelAnim.Play();
        }
        else
        {
            rightBarrelAnim.Play();
        }
    }
コード例 #9
0
ファイル: BulletUtils.cs プロジェクト: lishi500/LittleMage2
    public GameObject CreateBullet(Transform start, GameObject owner, Vector3 targetPos, Transform target, string name, BulletSize size = BulletSize.Small)
    {
        Role ownerRole = owner.GetComponent <Role>();

        GameObject bulletObj = PrafabUtils.Instance.create(prafabHolder.Bullet);
        Vector3    scale     = start.localScale;

        bulletObj.transform.position = start.position;
        bulletObj.transform.rotation = start.rotation;
        bulletObj.transform.LookAt(target);
        bulletObj.transform.localScale = scale;
        gizmosShootPoint = bulletObj.transform.position;


        SphereCollider bulletCollider = bulletObj.GetComponent <SphereCollider>();
        float          radius;

        bulletColliderRadius.TryGetValue(size, out radius);
        bulletCollider.radius = radius;

        Bullet bullet = bulletObj.GetComponent <Bullet>();

        bullet.bulletSpeed  = normalizeAttackSpeed(ownerRole.attribute.attackSpeed);
        bullet.creator      = owner;
        bullet.aimingTarget = target.gameObject;

        bullet.direction   = start.position - targetPos;
        gizmosReceivePoint = targetPos;

        GameObject bulletprojectilePrafab = prafabHolder.GetBullet(name, size);
        GameObject bulletImpectPrafab     = prafabHolder.GetBulletImpect(name, size);

        GameObject bulletprojectile = PrafabUtils.Instance.create(bulletprojectilePrafab);

        bulletprojectile.transform.SetParent(bulletObj.transform, false);


        bullet.enhancement  = GetBulletEnhancement();
        bullet.impectPrafab = bulletImpectPrafab;

        bullet.PreEnhancementProcess();
        bullet.ApplyForce();

        return(bulletObj);
    }
コード例 #10
0
    /// <summary>
    /// The method that fires bullet
    /// </summary>
    private void HandleFireBullet()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            GameObject bullet = Instantiate(bulletPrefab);
            bullet.transform.position = this.firingPoint.transform.position;
            bullet.transform.rotation = this.transform.rotation;

            Bullet bulletController = bullet.GetComponent <Bullet>();
            bulletController.ApplyForce(this.thrustDirection);

            EventsManager.Instance.TriggerOnBulletFired();
            AudioManager.Instance.Play(AudioClipName.ShipFire);
        }
    }
コード例 #11
0
ファイル: Ship.cs プロジェクト: wlicb/Asteroid-Unity-Game
    void Update()
    {
        float rotationInput = Input.GetAxis("Rotate");

        if (rotationInput != 0)
        {
            float rotationAmount = RotateDegreesPerSecond * Time.deltaTime;
            if (rotationInput < 0)
            {
                rotationAmount *= -1;
            }
            transform.Rotate(Vector3.forward, rotationAmount);
            float rotationz = transform.eulerAngles.z * Mathf.Deg2Rad;
            thrustDirection.x = Mathf.Cos(rotationz);
            thrustDirection.y = Mathf.Sin(rotationz);
        }
        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            GameObject bullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
            Bullet     script = bullet.GetComponent <Bullet>();
            script.ApplyForce(thrustDirection);
        }
    }