Input.GetTouch 获取触摸

2023-05-16

Input.GetTouch 获取触摸

static function GetTouch (index : int) : Touch

Description描述

Returns object representing status of a specific touch (Does not allocate temporary variables).

返回一个存放触摸信息的对象(不允许分配临时变量)。

1.手指移动控制物体移动

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class moveCube : MonoBehaviour {
    static int count;//定义touchCount数
    public GameObject particle_;//定义存放cube对象
    public Vector3 touchposition;//存储移动三维坐标值

	// Update is called once per frame
	void Update () {
        if (Input.touchCount > 0)
        {
            count += Input.touchCount;
        }
        if ((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)) //[color=Red]如果点击手指touch了  并且手指touch的状态为移动的[/color]
        {
            touchposition = Input.GetTouch(0).deltaPosition;  //[color=Red]获取手指touch最后一帧移动的xy轴距离[/color]
            particle_.transform.Translate(touchposition.x*0.01f, touchposition.y*0.01f, 0);//[color=Red]移动这个距离[/color]
        }
    }
    void OnGUI()
    {
        GUI.Label(new Rect(10, 10, 100, 30), "cishu:" + count.ToString());
        GUI.Label(new Rect(10, 50, 100, 30), touchposition.ToString());
    }
}

2.当用户在屏幕点击时实例一个炮弹

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public GameObject projectile;
	void Update() {
		int i = 0;
		while (i < Input.touchCount) {
			if (Input.GetTouch(i).phase == TouchPhase.Began)
				clone = Instantiate(projectile, transform.position, transform.rotation);

			++i;
		}
	}
}

3.当用户在屏幕点击时发射一条光线

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public GameObject particle;
	void Update() {
		int i = 0;
		while (i < Input.touchCount) {
			if (Input.GetTouch(i).phase == TouchPhase.Began) {
				Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
				if (Physics.Raycast(ray))
					Instantiate(particle, transform.position, transform.rotation);

			}
			++i;
		}
	}
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Input.GetTouch 获取触摸 的相关文章

随机推荐

  • C++ 应用程序 内存结构 --- BSS段,数据段,代码段,堆内存和栈

    转自 xff1a http hi baidu com C6 BF D6 D0 B5 C4 C5 AE CE D7 blog item 5043d08e741075f3503d922c html ld 时把所有的目标文件的代码段组合成一个代码
  • 4.1 简单题 - B 恭喜你

    当别人告诉你自己考了 x 分的时候 xff0c 你要回答说 xff1a 恭喜你考了 x 分 xff01 比如小明告诉你他考了90分 xff0c 你就用汉语拼音打出来 gong xi ni kao le 90 fen 输入格式 xff1a 输
  • <script>在页面代码上没有显示

    记录一下 导入js文件 xff0c 自己路径都没有问题 xff0c 为什么在浏览器查看页面代码没有自己写的那行js导入文件的代码呢 xff0c 原来 xff0c 是之前看着不舒服 xff0c 点了exclude xff0c exclude是
  • 利用Rust构建一个REST API服务

    利用Rust构建一个REST API服务 关注公众号 xff1a 香菜粉丝 了解更多精彩内容 Rust 是一个拥有很多忠实粉丝的编程语言 xff0c 还是很难找到一些用它构建的项目 xff0c 而且掌握起来甚至有点难度 想要开始学习一门编程
  • 安装cmake3.22

    升级cmake版本 脚本 span class token assign left variable file name span span class token operator 61 span cmake 3 22 0 yum era
  • stdout stderr 重定向到文件

    1 stdout stderr 重定向 1 stdout stderr 重定向 1 1 dup dup2 重定向到已打开文件 或 新文件1 2 freopen 重定向到新文件1 3 命令行重定向1 4 参考资料 1 1 dup dup2 重
  • 逆向基础-Windows驱动开发(一)

    Windows内核开发 第一个驱动程序 环境配置 xff1a 安装WDK xff1a WDK版本与SDK保持一致 然后记得把Spectre Mitigation给Disabled掉 xff0c 就不用去下载漏洞补丁了 然后在内核层 xff0
  • json-c 理解记录

    1 json c 理解记录 1 json c 理解记录 1 1 编译及说明1 2 特色1 3 使用 1 3 1 创建 xff0c 读写文件1 3 2 拷贝1 3 3 增改 1 3 3 1 字典增加元素1 3 3 2 数组增加修改元素 1 3
  • valgrind 简介(内存检查工具)

    1 valgrind 简介 1 valgrind 简介 1 1 概图1 2 特点1 3 使用示例1 4 参数说明 1 4 1 常用参数1 4 2 展示1 4 3 子进程 动态加载库及记录时机1 4 4 查错内存优化1 4 5 其他不常用1
  • GObject学习教程---第一章:GObject是有用并且简单的

    索引 xff1a https blog csdn net knowledgebao article details 84633798 本文是学习学习他人的博客的心得 xff08 具体详见 楼主见解 xff09 xff0c 如果源网站可访问的
  • GObject学习教程---第二章:模拟类的数据封装形式

    索引 xff1a https blog csdn net knowledgebao article details 84633798 本文是学习学习他人的博客的心得 xff08 具体详见 楼主见解 xff09 xff0c 如果源网站可访问的
  • 音视频中的PTS和DTS及同步

    相关索引 xff1a https blog csdn net knowledgebao article details 84776869 视频的播放过程可以简单理解为一帧一帧的画面按照时间顺序呈现出来的过程 xff0c 就像在一个本子的每一
  • h264和h265的区别

    相关索引 xff1a https blog csdn net knowledgebao article details 84776869 目录 1 H 264与H 265的主要差异 2 xff0c 压缩性能比较 3 各模块技术差异汇总 4
  • StreamEye使用说明

    编译相关索引 xff1a https blog csdn net knowledgebao article details 84973055 官网 xff1a https www elecard com products video ana
  • libc.so库简介

    相关链接 xff1a https blog csdn net knowledgebao article details 84315842 问题一 xff1a 比如不小心把软连接libc so 6删除了 xff0c 只要执行ldconfig
  • CentOS 7.6安装OpenStack Stein版本

    文章目录 一 前提1 1设置四节点1 2网络平台架构1 3准备环境 所有节点 1 3 1设置hosts1 3 2设置主机名1 3 3关闭 firewalld1 3 4关闭SELinux1 3 5设置静态IP1 3 6自定义yum源1 3 7
  • SQLite使用

    1 创建表 xff0c 以及更新表结构 public class MySQLiteOpenHelper extends SQLiteOpenHelper public MySQLiteOpenHelper Context context s
  • 数据结构实验之栈与队列八:栈的基本操作

    Problem Description 堆栈是一种基本的数据结构 堆栈具有两种基本操作方式 xff0c push 和 pop push一个值会将其压入栈顶 xff0c 而 pop 则会将栈顶的值弹出 现在我们就来验证一下堆栈的使用 Inpu
  • 解决SpringSecurity阻止ajax的POST和PUT请求,导致403Forbidden的问题

    解决SpringSecurity阻止ajax的POST和PUT请求 xff0c 导致403Forbidden的问题 参考文章 xff1a xff08 1 xff09 解决SpringSecurity阻止ajax的POST和PUT请求 xff
  • Input.GetTouch 获取触摸

    Input GetTouch 获取触摸 static function GetTouch index int Touch Description 描述 Returns object representing status of a spec