C# Unity3D-2D:在定位之前,是否将某个公共预制件的Time.timeScale设置为0?
所以我在游戏中有一个按钮,在给定的位置生成一个“塔”。生成塔时,塔的行为正常,我可以使用我的拖动脚本拖动它 我想知道在我第一次生成塔(仅针对该预制件)时如何将Time.timeScale设置为0,直到我再次单击以设置其位置 另外,单击按钮后,我想启用拖动脚本,设置位置,然后再次单击鼠标以禁用拖动脚本。这样我可以确保玩家不会因为额外的伤害而重新定位塔C# Unity3D-2D:在定位之前,是否将某个公共预制件的Time.timeScale设置为0?,c#,unity3d,unityscript,unity5,unity3d-2dtools,C#,Unity3d,Unityscript,Unity5,Unity3d 2dtools,所以我在游戏中有一个按钮,在给定的位置生成一个“塔”。生成塔时,塔的行为正常,我可以使用我的拖动脚本拖动它 我想知道在我第一次生成塔(仅针对该预制件)时如何将Time.timeScale设置为0,直到我再次单击以设置其位置 另外,单击按钮后,我想启用拖动脚本,设置位置,然后再次单击鼠标以禁用拖动脚本。这样我可以确保玩家不会因为额外的伤害而重新定位塔 using UnityEngine; using System.Collections; public class SpawnTower : Mo
using UnityEngine;
using System.Collections;
public class SpawnTower : MonoBehaviour {
public GameObject FrozenObject;
public Transform prefab;
public void OnClickSpawn()
{
for (int i = 0; i < 1; i++)
{
Instantiate(prefab, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);
}
}
//this part from here on DOES NOT WORK! It says that the GetComponent<>() method that is not valin in the given context
public void OnClick()
{
if (Input.GetMouseButtonUp(0))
{
GetComponent<DragEnemy>.enabled = false;
}
}
}
也许值得在游戏开发社区发布这个?这里有很多关于团结的问题:哦,谢谢你,伙计。我不知道这个网站上有gamedev部分。干杯
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(BoxCollider2D))]
public class DragEnemy : MonoBehaviour
{
private Vector3 screenPoint;
private Vector3 offset;
void OnMouseDown()
{
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
}