【发布时间】:2018-02-13 07:36:57
【问题描述】:
有谁知道如何使用鼠标单击来放大不同的游戏对象,并且在进行缩放后,游戏对象应该无法再次放大。目前我的代码能够扩大规模,但它不是我想要的。 这是我当前的代码:
public void ScaleForRuler()
{
transform.localScale += new Vector3 (3.0F, 0, 0.1F);
}
void OnMouseDown()
{
if (touch == false)
{
if(ruler.GetComponent<Collider>().name == "Ruler")
{
ScaleForRuler ();
touch = true;
Debug.Log (touch);
}
if(TriangleThingy.GetComponent<Collider>().name == "Triangle_Set_Square_Ruler")
{
ScaleForTriangleThingy ();
touch = true;
Debug.Log (touch);
}
if (Tsquare.GetComponent<Collider> ().name == "Tsquare")
{
if (LineR.GetComponent<Collider> ().name == "LineRight" || LineL.GetComponent<Collider> ().name == "LineLeft")
{
TsquareScaleForTB ();
touch = true;
Debug.Log (touch);
}
else if (LineB.GetComponent<Collider> ().name == "LineBottom" || LineT.GetComponent<Collider> ().name == "LineTop")
{
TsquareScaleForTB ();
touch = true;
Debug.Log (touch);
}
}
if (protractor.GetComponent<Collider> ().name == "Protractor")
{
ScaleForProtractor ();
touch = true;
Debug.Log (touch);
Debug.Log ("protractor scale");
}
}
}
【问题讨论】:
-
请解释为什么你的代码不是你想要的?
-
什么是“尺子”?另外,“它使用其他游戏对象的值以及标尺的值”是什么意思?
-
放大值,例如当你向上拖动标尺时,标尺确实放大了,但它使用了另一个游戏对象的值以及标尺的值。这是在为公共游戏对象放入游戏对象之后发生的,但是在删除除某个游戏对象之外的所有对象之后,它会给出未分配的引用错误。所以我想问我是否可以只使用一个脚本来控制许多差异对象的缩放。这些值是假定其他游戏对象使用的值。
-
如您所见,我已经为 4 个游戏对象添加了 debug.log,但由于某种原因,控制台显示了所有 4 个 debug.log 消息。
标签: c# unity3d scaling gameobject