Unity从所有标记的游戏对象中仅选择一个

问题描述 投票:0回答:1

我有100个带有名称标签(卡片)的多维数据集,我只希望我按下的多维数据集能够旋转。我的代码可以工作,但会旋转所有带有标签(卡片)的多维数据集。这是我的代码我只需要旋转整个(卡片)系列,仅标记我按下的对象

其他一切正常

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

public class SceneOneScript : MonoBehaviour
{


private bool canIRotate;
void Update()
{
    foreach (Touch touch in Input.touches)
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        if (Physics.Raycast(ray, out hit))
        {
            if (touch.phase == TouchPhase.Began)
            {

                if (hit.collider.tag == "card")
                {
                    canIRotate = true;

                }
            }
            if (touch.phase == TouchPhase.Ended)
            {
                canIRotate = false;
            }

            if (touch.phase == TouchPhase.Moved)
            {


                if (canIRotate == true)
                {
                       transform.LookAt(new Vector3(hit.point.x, hit.point.y,         transform.position.z));
                }


            }
        }






    }

}
}
android unity3d rotation game-engine touchscreen
1个回答
0
投票
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); RaycastHit hit; Debug.DrawRay(ray.origin, ray.direction * 100, Color.yellow, 100f); if(Physics.Raycast(ray, out hit)) { Debug.Log(hit.transform.name); if (hit.collider != null) { GameObject touchedObject = hit.transform.gameObject; Debug.Log("Touched " + touchedObject.transform.name); } }
© www.soinside.com 2019 - 2024. All rights reserved.