Uniyt3d物体跟随鼠标方向移动
来源:互联网 发布:ubuntu配置tftp服务器 编辑:程序博客网 时间:2024/05/16 12:37
第一个脚本实现效果:鼠标单机移动物体
基础部分终于看的差不多了。
要开始写代码,实现效果了~
程序基础不怎么好,慢慢来~~
点击鼠标左键 物体移动到鼠标位置
C#实现
using UnityEngine;
using System.Collections;
public class Script_01 : MonoBehaviour
{
private Vector3 world;
private float speed;//the move speed of object
void Start ()
{
}
void Update ()
{
Vector3 screenpos=Camera.main.WorldToScreenPoint(transform.position);//turn the coordinate of object from World to Screen
Vector3 m=Input.mousePosition;//the position of mouse
//when mouse click
if(Input.GetMouseButton(0))
{
m.z=screenpos.z;//give a z axis coordinate to mouse
world=Camera.main.ScreenToWorldPoint(m);//change to world coordinate
speed=30;
}
if(transform.position==world)
{
speed=0;
}
transform.LookAt(world);//let the object look at mouse
transform.Translate(Vector3.forward*speed*Time.deltaTime);
}
}
基础部分终于看的差不多了。
要开始写代码,实现效果了~
程序基础不怎么好,慢慢来~~
点击鼠标左键 物体移动到鼠标位置
C#实现
using UnityEngine;
using System.Collections;
public class Script_01 : MonoBehaviour
{
private Vector3 world;
private float speed;//the move speed of object
void Start ()
{
}
void Update ()
{
Vector3 screenpos=Camera.main.WorldToScreenPoint(transform.position);//turn the coordinate of object from World to Screen
Vector3 m=Input.mousePosition;//the position of mouse
//when mouse click
if(Input.GetMouseButton(0))
{
m.z=screenpos.z;//give a z axis coordinate to mouse
world=Camera.main.ScreenToWorldPoint(m);//change to world coordinate
speed=30;
}
if(transform.position==world)
{
speed=0;
}
transform.LookAt(world);//let the object look at mouse
transform.Translate(Vector3.forward*speed*Time.deltaTime);
}
}
- Uniyt3d物体跟随鼠标方向移动
- 游戏物体跟随鼠标移动
- Unity3d 物体跟随鼠标移动
- 【Unity】物体跟随鼠标移动
- Unity 代码实现物体跟随鼠标移动
- unity3d游戏物体跟着鼠标方向移动
- unity3d游戏物体跟着鼠标方向移动
- unity3d游戏物体跟着鼠标方向移动
- unity3d游戏物体跟着鼠标方向移动
- Unity鼠标出屏幕后 摄像机跟随鼠标方向移动
- 《鼠标点击物体,物体跟随光标移动》与《鼠标按住左键不放拖拽物体》
- Unity3D之物体跟随鼠标移动和旋转
- threejs中坐标系转换和实现物体跟随鼠标移动
- 3D场景中的物体跟随鼠标移动
- [脚本]实现游戏对象跟随鼠标方向移动
- [unity3d]如何实现游戏对象跟随鼠标方向移动
- [脚本]实现游戏对象跟随鼠标方向移动
- Unity 物体跟随鼠标点击移动,判断物体是否在移动
- 百炼2965 玛雅历
- 怎样设置Myeclipse的jsp页面为默认utf-8
- 国家对五险一金的交纳说明
- star地址收集
- 三层架构+存储过程实现分页
- Uniyt3d物体跟随鼠标方向移动
- 先参与创业,再主导创业:给想创业的毕业生的一封信
- Asp.NET网上商城向购物车添加新商品
- 主题:构造方法内部的多态方法的行为
- TD中的NAS非接入层和AS接入层
- VisualTree Ex (Part 2 of N——父子控件的查找)
- DirectFB编译环境
- 百度商搜研发一面
- ThinkPHP中Ajax验证表单