我想在我们单击或触摸对象时启用对象的发射。默认情况下,应在Unity中将其禁用。有人可以为我提供此问题的C#代码吗?
答案 0 :(得分:0)
也许是这样。
void Update () {
if (Input.GetMouseButtonDown(0)) {
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
if (hit.collider != null){
Material mymat = hit.collider.gameObject.GetComponent<Renderer>().material;
mymat.SetColor("_EmissionColor", Color.red);
}
}
}