在射击游戏中狙击一般都有一个红外线的效果。比如
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAS0AAAC+CAIAAADvBM7gAAAa10lEQVR4nO3d11cU2frw8fmXzmI4IiDqEQTJknMQBEFyztBEiRIkiuRuYpNREBAFBkFhCJJEFAURAREEEZVB3ov9sn81VdUt43RT3dXPs74Xs+aKavmsqt61q/jtPzrBEAQx22+M/wQQBIFDCGI+cAhBzAcOIYj5wCEEMR84hCDmA4cQxHzgEIKYDxxCEPOBQwhiPnAIQcwHDiGI+cAhBDEfOIQg5gOHEMR84BCCmA8cQhDzgUMIYj5wCEHMBw4hiPnAIQQxHziEIOYDhxDEfOAQgpgPHEIQ84FDCGI+cAhBzCdih4e/HTJ+SBAkdcH5EIKYT7wO4fQIQcfpJM6HoBGChHei16UAEoJoY+D7IWiEIFKMrdOARgjCMb9eCiAhiHmHKNAIyXKS4hB1+NshgIRkMMlyiAONkEwloQ5RcHqEZCSJdogCjRDrkwKHKKQRQEKsTGoc4kAjxL6kzyEKTo8Qm5JWhyjQCLEj6XaIA5CQVMcShyjQCElprHKIwhoBJCQtsdAhDjRC0hKbHaLg9AhJfux3iAKNkCQnKw5xABKSwGTOIQo0QhKVjDpEETUCSIjBZNohDjRCzAYO/y84PUJMBQ7JgUbo5AOHAgOQ0IkFDn8SaIROIHB4rEAjJNbA4T8LQELiCBz+SqAREm3g8NcjaQSQ0C8HDkUQaIT+ZeBQZMHpUUI6PN4w/nMSA4ciDjQy9sn/6jD+k/8HHIovAHlCn7PohsGjAIfiDTSK8bMVw2xubjJyLODwJKJqBJD/9iMVzxwcHOzu7i4sLJzw4YDDEw00iuAzFPPs7e1tbW0tLS2d5EGBQwaC0+Ovf3Tin2/fvn369Gltbe3Vq1cndlzgkLFA4z/+xMQ/BwcH3759297eXl9ff/v27ezs7MkcGjhkOFqNAJLmgxL//Pjx4/v377u7u1tbW2tra0tLS/Pz82NjYw8fPhT30YFDSQk0Cun79+8ng/DLly/b29sfP358//79mzd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TU1DQ0NLS0tHR0dfX19ZNLExMT0aMyOBpMzNjY2MjIyNDS8fPmyvr6+np6ejo4Old/p06eFfA88AYSH4BDgSfIQf/sVFRVVVFTOnTt34cKFixcvYpM6Ojq6hNE7Gl1dXW1tbS0tLU1NTQ0NDXV1dTU1NVVV1V/mJz6Eh+AQ4EnyUBnIy8srKCgoKSmdOXMGmUSjejRqR4PInT9//ty5cyoqKmfOnFFWVlZUVFRQUCBtiwGHUpyY/j1gSCOExO+//37q1CkFBYXTR6OoqKioqKikpKSkpHT69GkFBYVTp07Jy8tTt8JIFMJDcAjwJH9EQujfj1iPERwCPCkYpg2KF+EhOAR40jLgkLWJ+8OFEe2wUiAa2XJ4Mp8pjPiGlQgPWe/wxD5HmBMb9iE8ZJ/Dk/zsYBgcNiE8ZIHDE/68YCRnWMAPj/Q5ZOqTgpHkkSJytCMFDpn+iGBgxD6S6JDpzwQG5qRHIhwy/SHAwDA8zDhk+qhhYCRrTsgh04cJAyPRIy6HTB8XDIw0jcgcMn0gMDBSPL/ukOmfHAaGPfMPHDL9o8LAsHaEOWT6Z4OBkZX5DeDBwDA+vzH9A8DAwIBDGBgJGHAIA8P8/D8AOf2XK3+QCwAAAABJRU5ErkJggg==" alt="" />
鼠标指向哪个方向。就在哪个方向发射一条激光。这个用到了LineRenderer组建
我这里用射线检测。
创建一个圆柱体,添加LineRenderer组建。编写代码
using UnityEngine;
using System.Collections; public class ttw : MonoBehaviour
{
LineRenderer reader;
RaycastHit hit;
Ray ray;
void Awake()
{
reader = GetComponent<LineRenderer>();
} // Use this for initialization
void Start()
{
reader.SetVertexCount();//设置顶点
reader.SetWidth(0.1f, 0.1f); //设置开始和结束的宽
reader.SetColors(Color.red, Color.yellow); //设置开始和结束的颜色
reader.SetPosition(, transform.position);//设置开始坐标
} // Update is called once per frame
void Update()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit)) //当射线碰到物体
{
reader.SetPosition(, hit.point);
}
else
{
//以下效果相同,
//reader.SetPosition(1, ray.GetPoint(1000));
reader.SetPosition(, ray.direction * - transform.position);
}
}
}