Unity四元素运用之风向标跟随箭头
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WindVaneCom : MonoBehaviour
{
public static WindVaneCom instance
{
get;
private set;
}
public bool isOn = false;
public Camera cam;
public GameObject T;
public GameObject V;
public float PivotXY = 75f;
public float scoX = 220f;
public float scoY = 270f;
private float AtX;
private float AtY;
private Vector2 v2 = Vector2.one;
private Vector2 v2new = Vector2.one;
private Vector3 v3 = Vector3.one;
private Quaternion qua = Quaternion.identity;
void Awake()
{
instance = this;
}
public void SetGameobj(Camera ca, GameObject v, GameObject t)
{
cam = ca;
T = t;
V = v;
}
// Update is called once per frame
void Update()
{
if (isOn)
{
ObjectCom com = CreatureModel.Instance.GetCurrentObjCom();
if (com != null)
{
T = com.gameObject;
}
if (V == null || T == null)
{
Debug.Log("V==null||T==null");
return;
}
if (null != Camera.main)
{
cam = Camera.main;
v2 = cam.WorldToScreenPoint(T.transform.position);
}
else
{
Debug.Log("null == Camera.main");
// cam = Camera.current;
}
if ((v2.x >= (0 - scoX) && v2.x <= (Screen.width + scoX)) && (v2.y >= (0 - scoY) && v2.y <= (Screen.height + scoY)))
{
V.SetActive(false);
}
else
{
V.SetActive(true);
}
if (v2.x < -scoX)
{
AtX = PivotXY;
if (v2.y > 0 && v2.y < Screen.height)
{
AtY = v2.y;
V.SetActive(true);
}
}
if (v2.x > (Screen.width + scoX))
{
AtX = Screen.width - PivotXY;
if (v2.y > 0 && v2.y < Screen.height)
{
AtY = v2.y;
V.SetActive(true);
}
}
if (v2.y < -scoY)
{
AtY = PivotXY;
if (v2.x > 0 && v2.x < Screen.width)
{
AtX = v2.x;
V.SetActive(true);
}
}
if (v2.y > (Screen.height + scoY))
{
AtY = Screen.height - PivotXY;
if (v2.x > 0 && v2.x < Screen.width)
{
AtX = v2.x;
V.SetActive(true);
}
}
v2new.x = AtX;
v2new.y = AtY;
V.GetComponent<RectTransform>().anchoredPosition = v2new;
qua.SetLookRotation(V.transform.position, T.transform.position);
v3 = qua.eulerAngles;
// V.transform.rotation = Quaternion.Euler(0, 0, v3.z);
V.transform.rotation = Quaternion.Euler(v3.x, 0, v3.z);
}
else
{
if (V != null)
V.SetActive(false);
}
}
void OnDestory()
{
instance = null;
}
}
最新文章
- [R语言]R语言计算unix timestamp的坑
- Java关键字 ClassName.this(类名.this)的理解
- PHP数组合并+与array_merge的区别分析 &; 对多个数组合并去重技巧
- ubuntu 14.04 下svn + apache2 配置
- C#薪水和前途
- linux 接口地址全部清除才清理从此接口发出的下一跳路由
- css form 表单组对齐
- 一天一个Java基础——通过异常处理错误
- 剑指Offer17 二叉树的镜像
- 老老实实学习WCF[第二篇] 配置wcf
- Event Sourcing - ENode(二)
- org.hibernate.TransientObjectException:The given object has a null identifier
- node.js 的url模块
- NodeJS静态文件访问性能测试
- Python【每日一问】15
- linux上安装MongoDB副本集(带keyfile安全认证以及用户权限)
- java获取iPhone手机图片旋转角度处理
- Codeforces 524E Rooks and Rectangles 线段树
- Material Designer的低版本兼容实现(十)—— CheckBox &; RadioButton
- AQS源码分析
热门文章
- CodeForces 484B Maximum Value (数学,其实我也不知道咋分类)
- jQuery命名空间和自定义插件的的多种方法
- http verbs--Method Definitions
- HDU - 6112 2017百度之星初赛A 今夕何夕
- ICPC 2016 China Final J. Mr.Panda and TubeMaster【最大费用最大流】
- spring-eureka 源码解读----作为集群的eureka怎么样实现不做二次传播
- java实现对字符串和数字的冒泡排序
- react-native-video的使用
- php追加数组的问题
- Jmeter跨线程组传参