예제 #1
0
    // Use this for initialization
    void Start()
    {
        //車
        //Car1 = GameObject.Find("Car").gameObject;
        drivingCar1 = Car1.GetComponent <DrivingCar>();
        //drivingCar2 = Car2.GetComponent<DrivingCar>();
        //drivingCar3 = Car3.GetComponent<DrivingCar>();

        TLightGroupG = gameObject.transform.Find("TLightGroupG").gameObject;
        //Debug.Log(TLightGroupG.name);
        PointLightG = TLightGroupG.transform.Find("PointLightG").gameObject;
        //Debug.Log(PointLightG.name);

        greenLight = PointLightG.GetComponent <Light>();
        //greenLight = gameObject.transform.Find("TLightGroupG").gameObject.transform.Find("PointLightG").gameObject.GetComponent<Light>();
        yellowLight = gameObject.transform.Find("TLightGroupY").gameObject.transform.Find("PointLightY").gameObject.GetComponent <Light>();
        redLight    = gameObject.transform.Find("TLightGroupR").gameObject.transform.Find("PointLightR").gameObject.GetComponent <Light>();
        allTime     = greenTime + yellowTime + redTime;
        if (beginInRed)
        {
            cTime = greenTime + yellowTime + 1;
        }
    }
예제 #2
0
    private void shoot()
    {
        GameObject particles = Instantiate(shootingParticlesys, transform);

        particles.transform.localPosition = relativeBulletSpawnPos;
        particles.transform.parent        = null;
        //particles.GetComponent<ParticleShootingMinigun>().velocity = car.GetComponent<Rigidbody>().velocity;
        if (car.GetComponent <Rigidbody>() != null)
        {
            particles.GetComponent <ParticleShootingMinigun>().velocity = car.GetComponent <Rigidbody>().velocity;
        }
        else
        {
            particles.GetComponent <ParticleShootingMinigun>().velocity = car.GetComponent <OtherCar>().Velocity;
        }

        GameObject particlesCapsule = Instantiate(capsulesParticlesys, transform);

        particlesCapsule.transform.localPosition = relativeCapsuleSpawnPos;
        particlesCapsule.transform.parent        = null;
        //particlesCapsule.GetComponent<ParticleShootingMinigun>().velocity = car.GetComponent<Rigidbody>().velocity;
        if (car.GetComponent <Rigidbody>() != null)
        {
            particlesCapsule.GetComponent <ParticleShootingMinigun>().velocity = car.GetComponent <Rigidbody>().velocity;
        }
        else
        {
            particlesCapsule.GetComponent <ParticleShootingMinigun>().velocity = car.GetComponent <OtherCar>().Velocity;
        }

        if (car.GetType() == typeof(TestCar))
        {
            Ray rayShoot = new Ray(instEmpty.transform.position + car.transform.forward * 0.1f, car.transform.forward);
            Debug.Log("Ray: " + instEmpty.transform.position.ToString() + " Dir: " + car.transform.forward);
            RaycastHit[] hits = Physics.RaycastAll(rayShoot, 2000f);
            Debug.DrawRay(rayShoot.origin, rayShoot.direction * 100f, Color.blue, 1f);

            Damageable hitDamageable = null;
            float      nearest       = float.MaxValue;
            int        nearestIndex  = -1;
            for (int i = 0; i < hits.Length; i++)
            {
                if (hits[i].distance < nearest && hits[i].transform.gameObject.GetComponent <HasDamageable>() != null)
                {
                    hitDamageable = hits[i].transform.gameObject.GetComponent <HasDamageable>().damageable;
                    nearest       = hits[i].distance;
                    nearestIndex  = i;
                }
                else if (hits[i].distance < nearest && hits[i].transform.gameObject.GetComponentInParent <HasDamageable>() != null)
                {
                    hitDamageable = hits[i].transform.gameObject.GetComponentInParent <HasDamageable>().damageable;
                    nearest       = hits[i].distance;
                    nearestIndex  = i;
                }
            }

            //particles.GetComponent<ParticleShootingMinigun>().destroyTime = nearest / 600.0f;

            if (hitDamageable != null)
            {
                //hitDamageable.Damage(damage);

                DrivingCar drivingCar = (DrivingCar)hitDamageable;

                //if (hitDamageable.GetType() == typeof(DrivingCar))
                if (drivingCar != null)
                {
                    multiManager.Network.SendDamagePlayer(multiManager.OwnID, drivingCar.ID, 1f);
                    multiManager.Network.SendSpawnBulletImpact(multiManager.OwnID, hits[nearestIndex].point, 0);
                }
            }
        }
    }