相机选择物体,选中之后,相机会沿射线相机平移到物体周围,这是我一个小伙伴写的,现在把它发表出来,十分感觉小伙伴的支持!
注意:物体必须有collider组件
代码:
using UnityEngine;
using System.Collections;
using System;
public class RayToMove : MonoBehaviour
{
Vector3 Target = new Vector3();
private bool NoTarget = true;
public float speed=100;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0)) {
Ray MoveRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit RayInf = new RaycastHit();
if (Physics.Raycast(MoveRay, out RayInf))
{
if (RayInf.collider.name