示例#1
0
    private void AddTransparency(GameObject model)
    {
        WallTransparency wt = model.AddComponent <WallTransparency>();

        wt.Foundation   = _renderCamera.transform.GetChild(0).GetChild(0);
        wt.PlayerCamera = _renderCamera.transform.GetChild(1);
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (target != null)
        {
            Vector3 desiredPosition = transform.position;

            Vector3 targetPosition = target.transform.position + positionOffset;

            float directionToTargetX = targetPosition.x - transform.position.x;
            float directionToTargetZ = targetPosition.z - transform.position.z;
            float distanceToTargetX  = Mathf.Abs(directionToTargetX);
            float distanceToTargetZ  = Mathf.Abs(directionToTargetZ);

            // 相机与玩家离得太远了。
            if (distanceToTargetX > followDistanceX)
            {
                desiredPosition.x = transform.position.x + (Mathf.Min(distanceToTargetX - followDistanceX, followSpeed * Time.deltaTime) * Mathf.Sign(directionToTargetX));
            }

            if (distanceToTargetZ > followDistanceZ)
            {
                desiredPosition.z = transform.position.z + (Mathf.Min(distanceToTargetZ - followDistanceZ, followSpeed * Time.deltaTime) * Mathf.Sign(directionToTargetZ));
            }

            VelocityLimit playerVelocityLimit = target.GetComponent <VelocityLimit>();
            Rigidbody     playerRigidbody     = target.GetComponent <Rigidbody>();
            Camera        playerCamera        = gameObject.GetComponent <Camera>();
            Assert.AreNotEqual(null, playerCamera);
            if (playerVelocityLimit == null || playerRigidbody == null)
            {
                desiredPosition.y = targetPosition.y;
            }
            else
            {
                desiredPosition.y = targetPosition.y;

                float playerVelocity = playerRigidbody.velocity.magnitude;
                float desiredSize    = minSize + (playerVelocity / playerVelocityLimit.GetMaxVelocity() * (maxSize - minSize));
                desiredSize = Mathf.Lerp(playerCamera.orthographicSize, desiredSize, sizeChangeSpeed * Time.deltaTime);
                playerCamera.orthographicSize = Mathf.Clamp(desiredSize, minSize, maxSize);
            }

            transform.position = desiredPosition;
        }

        // Bounds checking.
        transform.position = new Vector3(LimitPosition(transform.position.x, minimumPosition.x, maximumPosition.x),
                                         LimitPosition(transform.position.y, minimumPosition.y, maximumPosition.y),
                                         LimitPosition(transform.position.z, minimumPosition.z, maximumPosition.z));

        // Raycast to the player. If there are obstacles between, turn them transparent.
        Vector3 directionToPlayer = target.transform.position - gameObject.transform.position;
        float   raycastDistance   = directionToPlayer.magnitude;

        RaycastHit[] result = Physics.RaycastAll(transform.position, directionToPlayer, raycastDistance);
        for (int i = 0; i < result.Length; ++i)
        {
            Collider         hitCollider         = result[i].collider;
            GameObject       hitGameObject       = hitCollider.gameObject;
            WallTransparency hitWallTransparency = hitGameObject.GetComponent <WallTransparency>();
            if (hitWallTransparency == null)
            {
                continue;
            }

            hitWallTransparency.TurnTransparent();
            //Debug.Log("PlayerCamera::Update - Turning Object Transparent.");
        }
    }