本文主要是介绍广告牌效果的C#实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言
- 这个效果是在以前的项目时候,特效那边想要一个广告牌效果
- 但是我不懂什么是广告牌
- 两个人沟通半天,才把东西做出来。
代码如下
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;[ExecuteInEditMode]
public class LooAt : MonoBehaviour
{public bool IsActive;public Transform targetCamera;// Start is called before the first frame updatevoid Start (){
#if UNITY_EDITOREditorApplication.update += LookAtCamera;
#endif}private void Update (){if (Input.GetKeyDown (KeyCode.A)){Debug.Log (transform.localEulerAngles.x);}}void LookAtCamera (){if (IsActive && targetCamera != null){Vector3 curLocalTarPos = transform.InverseTransformPoint (targetCamera.position);Vector3 newPos = new Vector3 (curLocalTarPos.x, 0, curLocalTarPos.z);float angle = Vector3.Angle (Vector3.forward, newPos);float angleDir = Vector3.Cross (Vector3.forward, newPos).y;angleDir = angleDir == 0 ? angleDir : angleDir / Mathf.Abs (angleDir);angle = angle * angleDir;transform.Rotate (Vector3.up, angle, Space.Self);}}private void OnDestroy (){
#if UNITY_EDITOREditorApplication.update -= LookAtCamera;
#endif}}
这篇关于广告牌效果的C#实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!