根据参考资料1 里面的,下载 projector 组件
ProjectorCustom Shader在参考资料10
结合参考资料11查看
----------------------------------------------------------------------------------------------------------------------------------------
如果 Projector投影仪 如下图设置
设置后效果如图所示
根据 参考资料2,3,4,5,6,使用画图工具 画一个 自己 的圆环
如果设置如下
效果如下所示
新建材质球
----------------------------------------------------------------------------------------------------------------------------------------
设置如下所示
TestRotation 代码如下所示:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestRotation : MonoBehaviour {
private Vector3 rotationMask = new Vector3(0, 1, 0); //which axes to rotate around
private float rotationSpeed = 5.0f; //degrees per second
public GameObject rotateAround;
private Transform rotateAroundObject;
private void Awake()
{
rotateAroundObject = rotateAround.transform;
}
// Update is called once per frame
void Update () {
if (rotateAroundObject)
{//If true in the inspector orbit :
transform.RotateAround(rotateAroundObject.transform.position,
rotationMask, rotationSpeed * Time.deltaTime);
}
else
{//not set -> rotate around own axis/axes:
transform.Rotate(new Vector3(
rotationMask.x * rotationSpeed * Time.deltaTime,
rotationMask.y * rotationSpeed * Time.deltaTime,
rotationMask.z * rotationSpeed * Time.deltaTime));
}
}
}
----------------------------------------------------------------------------------------------------------------------------------------
1. X,Z的坐标 在一定 的范围 内 满足 条件 ,停止。
2. 比较 两条 直线 (玩家-鼠标,箭头-圆)的角度。Vector3.Angle(line_m_, line_a_);
这样进行设置 ,就可以 使得 Arrow 对象 ,在 X 在一定 范围 的时候 ,就停下来
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestRotation : MonoBehaviour
{
private Vector3 rotationMask = new Vector3(0, 1, 0); //which axes to rotate around
private float rotationSpeed = 10.0f; //degrees per second
public GameObject centerGO;
private Transform centerGO_trans;
private Vector3 centerGO_pos;
public GameObject arrowGO;
private Transform arrowGO_trans;
private Vector3 arrowGO_pos;
private void Awake()
{
UpdatePoint();
}
// Update is called once per frame
void Update()
{
UpdatePoint();
if (arrowGO_pos.x < 1 && arrowGO_pos.x > 0.9)
{
Debug.Log("111");
}
else
{
if (centerGO.transform)
{//If true in the inspector orbit :
transform.RotateAround(centerGO_pos,
rotationMask, rotationSpeed * Time.deltaTime);
}
else
{//not set -> rotate around own axis/axes:
arrowGO_trans.Rotate(new Vector3(
rotationMask.x * rotationSpeed * Time.deltaTime,
rotationMask.y * rotationSpeed * Time.deltaTime,
rotationMask.z * rotationSpeed * Time.deltaTime));
}
}
}
private void UpdatePoint()
{
centerGO_trans = centerGO.transform;
centerGO_pos = centerGO_trans.position;
arrowGO_trans = arrowGO.transform;
arrowGO_pos = arrowGO_trans.position;
}
}
----------------------------------------------------------------------------------------------------------------------------------------
当下面 的这个 参数 为 -1 的时候,逆时针 旋转,为1 的时候,顺时针旋转
private Vector3 rotationMask = new Vector3(0, -1, 0); //which axes to rotate around
当
当 line_m 和 line_a 都 normalized。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestRotation : MonoBehaviour
{
private Vector3 rotationMask = new Vector3(0, 1, 0); //which axes to rotate around
private float rotationSpeed = 10.0f; //degrees per second
public GameObject centerGO;//中心
private Transform centerGO_trans;
private Vector3 centerGO_pos;
public GameObject arrowGO;//箭头
private Transform arrowGO_trans;
private Vector3 arrowGO_pos;
public GameObject playerGO;//玩家
private Transform playerGO_trans;
private Vector3 playerGO_pos;
private Vector3 mouse_pos;//鼠标
private Vector3 line_m;//鼠标 到 玩家的 向量
private Vector3 line_m_;//使其 Y 为0
private Vector3 line_a;//箭头 到 中心 的向量
private Vector3 line_a_;//
private void Awake()
{
UpdatePoint();
}
// Update is called once per frame
void Update()
{
Ray MouseRay = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition);//场景中必须含有 Canvas,否则无效
RaycastHit raycastHit;//互动物体 碰撞到的物体
Physics.Raycast(MouseRay, out raycastHit, 5000);
if (null != raycastHit.transform)
{
UpdatePoint();
mouse_pos = raycastHit.point;
line_m = new Vector3(mouse_pos.x, 0, mouse_pos.z) - new Vector3(playerGO_pos.x, 0, playerGO_pos.z);
line_m_ = line_m.normalized;
line_a = new Vector3(arrowGO_pos.x, 0, arrowGO_pos.z) - new Vector3(centerGO_pos.x, 0, centerGO_pos.z);
line_a_ = line_a.normalized;
Debug.Log(" "+ mouse_pos);
if (line_a_.x > (line_m_.x -0.1f )
&& line_a_.x < (line_m_.x + 0.1f)
&& line_a_.z > (line_m_.z - 0.1f)
&& line_a_.z < (line_m_.z + 0.1f)
)//就不旋转,否则 则旋转
{
Debug.Log("111");
}
else
{
if (centerGO.transform)
{//If true in the inspector orbit :
transform.RotateAround(centerGO_pos,
rotationMask, rotationSpeed * Time.deltaTime);
}
else
{//not set -> rotate around own axis/axes:
arrowGO_trans.Rotate(new Vector3(
rotationMask.x * rotationSpeed * Time.deltaTime,
rotationMask.y * rotationSpeed * Time.deltaTime,
rotationMask.z * rotationSpeed * Time.deltaTime));
}
}
}
}
private void UpdatePoint()
{
centerGO_trans = centerGO.transform;
centerGO_pos = centerGO_trans.position;
arrowGO_trans = arrowGO.transform;
arrowGO_pos = arrowGO_trans.position;
playerGO_trans = playerGO.transform;
playerGO_pos = playerGO_trans.position;
}
}
----------------------------------------------------------------------------------------------------------------------------------------
当发生旋转的 时候 Arrow对象 的 Rotattion 的Z 发生变化 ,并且 Position 的 X,Z坐标发生变化。只在 世界坐标系 的 X Z 平面上发生变化
所以,要想实现 鼠标 移动 使得 技能指示器 skill indicator 跟随鼠标 的变化 ,而旋转
就得改变 Arrow 对象 的Rotation 的 Z ,以及 Position 的 X 和Z 轴坐标。
参考资料:
1.[Unity&特效]使用Projector投影仪组件在哪里下载
2.
3.
4.
5.
6.
7.
http://blog.csdn.net/bulademian/article/details/73504204
8.unity 计算两点角度
9.
10.Unity 5 使用Projector实现纹理投射
11.[Unity]2D&3D物体指向indicator鼠标,技能指示器 基础
12.
13.