Unity3D学习笔记(1)-简单的unity&n…

这篇Unity3D学习笔记介绍了如何在场景中实现点击屏幕时显示手指位置的功能。通过使用Unity的Input模块检测鼠标点击,结合OnGUI方法绘制手指图像,实现了最多五个触摸点的追踪和显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先,安装好Unity3D; 然后,绑定MonoDevelop。

为了调试方便,把MonoDevelop调试绑定到unity3D吧
Unity3D学习笔记(1)-简单的unity <wbr>2d贴图

弹出窗口,选择右下角attach,OK可以使用MonoDevelop调试了。

强烈建议先熟悉一个 Unity3D入门教程,其他的就不说了。

建议用C#写哦,JS不太规范.

因为没有安装任何插件,那么还是用代码来实现:

  1. using UnityEngine;
  2. using System.Collections;
  3. public class clickscreen : MonoBehaviour {
  4.     // 在外部拖拽图片绑定用public
  5.     public Texture tex_menu_;    // 添加背景图片
  6.     public Texture tex_finger_;    // 添加手指图片
  7.     private Vector3[] current_pos_ = new Vector3[5] ;    // 创建五个位置,为什么呢?因为只支持五个触摸点,呵~呵
  8.     private int    touch_count_;    // 点击计数
  9.    
  10.     // Use this for initialization
  11.     void Start () {
  12.         // 这里是初始化哦
  13.     }
  14.    
  15.     // Update is called once per frame
  16.     void OnGUI () {
  17.         // 这里是一直持续描绘
  18.        
  19.         GUI.DrawTexture( new Rect(0,0,640,960), tex_menu_);    // 描绘背景贴图
  20.        
  21.         // 保护后庭
  22.         if( touch_count_>0 )
  23.         {
  24.             for( int i= 0; i
  25.             {
  26.                 GUI.DrawTexture(new Rect(current_pos_[i].x, 960 - current_pos_[i].y, 106, 106), tex_finger_);
  27.             }
  28.         }
  29.     }
  30.     void Update()
  31.     {
  32.         // 这里是一直持续更新
  33.         if(Input.GetMouseButtonDown(0))
  34.         {
  35.             ++ touch_count_;
  36.             current_pos_[touch_count_-1] = Input.mousePosition;
  37.         }
  38.     }
  39. }

同时把这个文件拖拽至Main Camera,然后把准备好的背景图和按钮图与public Texture tex_menu_、public Texture tex_finger_链接起来,build and run 看看效果把,只有点击机会哦!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值