我有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));
}
}
}
}
}
}
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);
}
}