English 中文(简体)
我怎么能够用文字接触一名学者的游戏吗?
原标题:How can I access a Collider s GameObject in script?

我正在团结中进行心脏游戏。 我在计划使用c#时将卡片作为游戏物体。 我想知道,如何使每个物体在 mo子点上移动,即与Rycast公司一起尝试,但并未发挥作用。 我试图接触母 Game,这完全是sh子的包.,并 s合物/异构体,我想通过这些物品接触一个孩子的游戏(改变立场)。 是否有办法解决这一问题,或者是否有更好的办法以某种其他方式做到这一点?

最新情况:

if (Input.GetMouseButton (0)) {                    
    RaycastHit hit = new RaycastHit ();
    Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    if (Physics.Raycast (ray, out hit)) { 
        print (hit.collider.gameObject.name);
    }
} 
问题回答

<编码>Input.GetMouseButton(0)。

您试图使用<条码>Input.GetMouseButton(0),该编码登记了每一条术语,而不是<条码>Input.GetMouseButtonDown(0),后者只登记用户点击的第一个框架。

Example code:

if (Input.GetMouseButtonDown(0))
    print ("Pressed");
else if (Input.GetMouseButtonUp(0))
    print ("Released");

以及

if (Input.GetMouseButton(0))
    print ("Pressed");
else
    print ("Not pressed");

如果是这样作,则试图取代<代码>if(物理)。 Raycast(光线,点击){ with if(物理)。 Raycast (ray, out at,1000){

I stumbled upon this problem aswell, try this instead (Btw u can use GetMouseButtonUp aswell instead)

if (Input.GetMouseButtonDown (0)) 
{                    
RaycastHit hit = new RaycastHit ();
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit)) { 
    print (hit.collider.transform.gameObject.name);
iii

iii

For some way it can be accessed via Transform, it did the the trick for me! And if you want to access the parent:

hit.collider.transform.parent.gameObject;

如今,儿童是一小trick:

// You either access it by index number
hit.collider.transform.getChild(int index);
//Or you could access some of its component ( I prefer this method)
hit.collider.GetComponentInChildren<T>();

Hope I could help. Cheers!





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签