コード例 #1
0
        //function call to fire the object
        public void Shoot(int srcL, float srcR, Transform shootPoint, AttackInstance aInstance = null, AimInfo aimInfo = null)
        {
            Init();

            thisObj.SetActive(true);

            //cached all the passed information lcoally
            attInstance = aInstance;
            srcLayer    = srcL;         //the layer of the shooting unit (so we know it's from player or AI)
            srcRange    = srcR;         //the range of the shooting unit (so we know when to stop)

            state             = _State.Shot;
            shootTime         = Time.time;      //to track how long the shoot object is has been
            travelledDistance = 0;              //to track how far the shoot object is has been fired

            //if there's any hideObject, set it to true (it's probably set to false when the shoot-object last hit something)
            if (hideObject != null)
            {
                hideObject.SetActive(true);
            }

            //instantiate the shoot effect
            ShootEffect(thisT.position, thisT.rotation, shootPoint);

            if (type == _SOType.Simple || type == _SOType.Homing)
            {
                //if(aInstance!=null && thisCollider.enabled){
                //~ Physics.IgnoreCollision(aInstance.srcUnit.GetCollider(), thisObj.GetComponent<Collider>(), true);
                //Debug.Log("collision avoidance with shooter unresolved");
                //Physics.IgnoreCollision(srcCollider, thisCollider, true);
                //}

                // for homing shootobject, the shootobject needs to be aiming at some position, or a specific unit
                if (type == _SOType.Homing)
                {
                    if (aimInfo.targetT != null)
                    {
                        targetUnit = aimInfo.unit;
                    }

                    targetPos   = aimInfo.hitPoint + new Vector3(Random.value - 0.5f, 0, Random.value - 0.5f) * 2 * spread;
                    initialPos  = shootPoint.position;
                    initialDist = Vector3.Distance(targetPos, initialPos);

                    curveMod = Random.Range(0, 2f);
                    dummyPos = thisT.TransformPoint(Vector3.forward * speed * 5);
                    dummyPos = (targetPos + dummyPos) / 2;
                }
            }
            else if (type == _SOType.Beam)
            {
                //if(attachedToShootPoint) transform.parent=shootPoint;
                thisT.parent = shootPoint;
                ObjectPoolManager.Unspawn(thisObj, beamDuration - .01f);
            }
            else if (type == _SOType.Point)
            {
                StartCoroutine(PointRoutine(aimInfo));
            }

            //update the layermask used to do the hit detection in accordance to rules set in GameControl
            UpdateSphereCastMask(!GameControl.SOHitFriendly(), !GameControl.SOHitShootObject(), !GameControl.SOHitCollectible());
        }