Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CameraScript : MonoBehaviour
- {
- Transform lastWall;
- public float distFromPlayer = 5;
- public float speed = 20;
- public LayerMask wallMask;
- public Transform player;
- void Start ()
- {
- }
- void FixedUpdate ()
- {
- Vector3 targetPos = player.position - player.forward * distFromPlayer;
- targetPos.y = player.position.y + 3;
- transform.position = Vector3.Lerp(transform.position, targetPos, speed * Time.fixedDeltaTime);
- transform.LookAt(player.position);
- RaycastHit hit;
- Physics.Linecast(transform.position, player.position, out hit, wallMask);
- Debug.DrawLine(transform.position, player.position);
- if (lastWall != null && lastWall != hit.transform)
- {
- SetAlphaOnObj(lastWall, 1f);
- }
- if(hit.transform != null)
- {
- SetAlphaOnObj(hit.transform, 0.5f);
- lastWall = hit.transform;
- }
- }
- void SetAlphaOnObj(transform trans, float alpha)
- {
- Material mat = trans.GetComponent<MeshRenderer>().materials[0];
- Color c = mat.color;
- c.a = alpha;
- mat.color = c;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement