コード例 #1
0
    void SpawnCannonball()
    {
        smokeFX.Play();
        Cannonball ball = Instantiate(CannonballPrefab, transform.position, Quaternion.identity);

        ball.GetComponent <Rigidbody>().AddForce(transform.TransformVector(new Vector3(1f, 0f, 0f)) * Force, ForceMode.Impulse);

        Destroy(ball, 3f);
    }
コード例 #2
0
ファイル: Cannon.cs プロジェクト: jamesrenhoulee/Clash
    void Fire()
    {
        attackCooldownTimer = DELAYBETWEENATTACKS;
        Vector3    itemSpawnPos  = new Vector3(transform.position.x, transform.position.y + 1.85f, transform.position.z) + transform.forward * 3f;
        Vector3    dir           = targetUnit.transform.position - itemSpawnPos;
        Cannonball newCannonball = Instantiate(cannonballPrefab, itemSpawnPos, Quaternion.identity);

        newCannonball.Initialize(team, DAMAGE);
        NetworkServer.Spawn(newCannonball.gameObject);
        //newShuriken.transform.Rotate(90, 0, 0);
        newCannonball.GetComponent <Rigidbody>().AddForce(Vector3.Normalize(dir) * 50f, ForceMode.Impulse);
    }
コード例 #3
0
ファイル: Cannon.cs プロジェクト: dpid/PIGDefense
    public void Fire()
    {
        if (isActiveAndEnabled)
        {
            Cannonball cannonball = cannonballPool.GetCannonball();

            if (cannonball != null)
            {
                cannonball.gameObject.SetActive(true);
                cannonball.transform.position      = transform.position;
                cannonball.transform.localRotation = Quaternion.identity;

                Vector3 force  = transform.forward * strength;
                Vector3 torque = new Vector3(Random.Range(1.0f, 10.0f), Random.Range(1.0f, 10.0f), Random.Range(1.0f, 10.0f));

                Rigidbody cannonballRigidbody = cannonball.GetComponent <Rigidbody>();
                cannonballRigidbody.AddForce(force, ForceMode.Impulse);
                cannonballRigidbody.AddTorque(torque);
            }
        }
    }