简体   繁体   English

触摸特定对象时实例化对象

[英]Instantiating an Object when touching a Specific Object

I'm trying to make a C# Script responsible for instantiating and shooting a ball whenever the Mini-gun (an Object shown in the Camera's FOV) is Touched from a Mobile Device.我正在尝试制作一个 C# 脚本,负责在移动设备触摸迷你枪(在相机的 FOV 中显示的对象)时实例化和射击球。

I already set an Empty Game Object at the End of the Mini Gun so the Instantiate() Method can use its transform for the new instantiated ball.我已经在迷你枪的末端设置了一个空游戏对象,因此 Instantiate() 方法可以将其变换用于新的实例化球。

I know the the Instantiate() Method as well as the RigidBody.Addforce() to shoot the instantiated ball.我知道 Instantiate() 方法以及 RigidBody.Addforce() 来射击实例化的球。 I just want the (Touch Input) Codes so when the Player touches the Mini-gun shown in the Camera FOV, the Gun shoots a Ball.我只想要(触摸输入)代码,所以当玩家触摸摄像机 FOV 中显示的迷你枪时,枪会射出一个球。

It is viewed upon poorly here to ask directly for code.直接索取代码在这里被认为很糟糕。

It is better to ask for help that points you in the right direction, as it will help you learn.最好寻求为您指明正确方向的帮助,因为这会帮助您学习。

The tools in Unity that will help you achieve what you are after are: Unity 中可帮助您实现目标的工具有:

Physics.Raycast() Physics.Raycast()

Camera.ScreenPointToRay() Camera.ScreenPointToRay()

There is a lot of documentation for these two methods.这两种方法有很多文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM