【发布时间】:2023-03-19 11:55:01
【问题描述】:
我有 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));
}
}
}
}
}
}
【问题讨论】:
-
SceneOneScript 附加的 GameObject 的 cubes 子对象吗?
-
不,他们不是
-
一定是在那个有Camera的GameObject上?
-
要最终确定答案,如果您的原始问题已解决,请记住接受并投票,如果您有其他问题,请提出新问题:stackoverflow.com/help/someone-answers
标签: android unity3d rotation game-engine touchscreen