コード例 #1
0
    // Use this for initialization
    void Start()
    {
        this.baseTrailLength = this.baseTrailLength * this.arenaSettings.trailLengthMultiplyer;

        this.characterController = this.gameObject.GetComponent<CharacterController>();
        if (this.cameraTransform != null)
            this.cameraPos = this.cameraDistance.x * this.transform.right + this.cameraDistance.y * this.transform.up + this.cameraDistance.z * this.transform.forward;
        this.moveDirection = this.transform.forward;
        this.gravityDirection = -this.transform.up;

        this.lineRenderer = this.GetComponentInChildren<OptimizedLineRenderer>();
        this.vehicleMesh = this.transform.Find("VehicleMeshes").gameObject;

        if (this.arenaSettings != null)
            this.gridSize = this.arenaSettings.gridSize;

        this.trailCollisionObject = new GameObject("Trail Collision");
        TrailCollision trailCollision = this.trailCollisionObject.AddComponent<TrailCollision>();
        trailCollision.owner = this;

        this.UpdateColors();

        // Snap player to a close node point on grid
        RaycastHit raycastHit;
        if (Physics.Raycast(new Ray(this.transform.position, this.gravityDirection), out raycastHit, Mathf.Infinity, DriverController.drivableLayerMask /*| DriverController.nonDrivableLayerMask*/))
        {
            Vector3 localPos = raycastHit.transform.InverseTransformDirection(this.transform.position);

            localPos += raycastHit.transform.localScale * 0.5f;

            localPos /= this.gridSize;
            localPos.x = (int)(localPos.x) + 0.5f + ((raycastHit.transform.localScale.x / this.gridSize) % 1.0f);
            localPos.z = (int)(localPos.z) + 0.5f + ((raycastHit.transform.localScale.z / this.gridSize) % 1.0f);
            localPos *= this.gridSize;

            localPos -= raycastHit.transform.localScale * 0.5f;

            Vector3 nodePos = localPos;
            Vector3 zeroLocal = raycastHit.transform.InverseTransformDirection(raycastHit.transform.position);

            localPos.y = zeroLocal.y + this.characterController.radius + 0.1f;
            nodePos.y = zeroLocal.y;

            this.transform.position = raycastHit.transform.TransformDirection(localPos);
            nodePos = raycastHit.transform.TransformDirection(nodePos);

            this.nodeList.Add(new PathNode(nodePos, raycastHit.transform.up, raycastHit.transform.up, this.mainColor));
            this.nodeList.Add(new PathNode(nodePos, raycastHit.transform.up, raycastHit.transform.up, this.mainColor));
        };
    }
コード例 #2
0
    void KillRPC(int killer, int killedPlayer)
    {
        this.invincibleTimer = 0.0f;
        this.boostTime = 0.0f;

        if (this.killed)
            return;

        this.killed = true;

        this.SendMessage("OnPlayerDied");

        this.harmlessTimer = 100.0f;
        this.UpdateColors();

        if (this.lineRenderer != null)
            this.lineRenderer.gameObject.transform.parent = null;

        UnityEngine.Object explosion = UnityEngine.Object.Instantiate(this.explosionPrefab, this.transform.position, this.transform.rotation);
        foreach (string systemName in this.explosionParticlesNames){
            ParticleSystem particleSystem = ((Transform)(explosion)).Find(systemName).gameObject.particleSystem;
            particleSystem.startColor = 0.1f * particleSystem.startColor + 0.9f * this.mainColor;
            particleSystem.startColor = new Color(particleSystem.startColor.r, particleSystem.startColor.g, particleSystem.startColor.b, 1.0f);
        }
        //ParticleSystem particleSystem = ((Transform)(explosion)).gameObject.GetComponent<ParticleSystem>();
        //ParticleSystem particleSystem = this.explosionPrefab.Find(this.explosionParticlesName).gameObject.particleSystem;
        //particleSystem.startColor = 0.1f * particleSystem.startColor + 0.9f * this.mainColor;
        //particleSystem.startColor = new Color(particleSystem.startColor.r, particleSystem.startColor.g, particleSystem.startColor.b, 1.0f);
        //particleSystem = particleSystem.gameObject.GetComponentInChildren<ParticleSystem>();
        //particleSystem.startColor = 0.1f * particleSystem.startColor + 0.9f * this.mainColor;
        //particleSystem.startColor = new Color(particleSystem.startColor.r, particleSystem.startColor.g, particleSystem.startColor.b, 1.0f);
        UnityEngine.Object.Destroy(((Transform)(explosion)).gameObject, 3.0f);

        if (this.lineRenderer != null)
        {
            UnityEngine.Object.Destroy(this.lineRenderer.gameObject, this.killTimer);
            this.lineRendererKilled = this.lineRenderer;
            this.lineRenderer = null;
        }

        if (this.vehicleMesh != null)
        {
            UnityEngine.Object.Destroy(this.vehicleMesh);
            this.vehicleMesh = null;
        }

        for (int i = 0; i < this.colliderList.Count; i++)
        {
            if (this.colliderList[i] != null)
            {
                this.colliderList[i].collider.enabled = false;
                this.colliderList[i] = null;
            }
        }
        if (this.trailCollisionObject != null)
        {
        //#if UNITY_EDITOR
        //            UnityEditor.EditorApplication.ExecuteMenuItem("Edit/Pause");
        //            UnityEngine.Object.Destroy(this.trailCollisionObject, 1.0f);
        //#else
        //            UnityEngine.Object.Destroy(this.trailCollisionObject);
        //#endif
            UnityEngine.Object.Destroy(this.trailCollisionObject);
            this.trailCollisionObject = null;
        }

        if (this.characterController != null)
            this.characterController.enabled = false;

        this.KillSideBlades();
    }