Created
June 15, 2016 10:47
-
-
Save s2kw/58b6a22daa125b34a1af882b43229300 to your computer and use it in GitHub Desktop.
毎日出題の3日目第一問の答え
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CreatePrimitiveByMouse : MonoBehaviour { | |
GameObject primitive = null; | |
void Update () { | |
if (Input.GetMouseButton(0)) | |
{ | |
// マウス位置から発生するRayを作成 | |
var ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
// 当たり確認オブジェクト | |
RaycastHit hit; | |
if (Physics.Raycast(ray, out hit, float.MaxValue)) | |
{ | |
if (primitive == null) | |
{ | |
primitive = GameObject.CreatePrimitive(PrimitiveType.Cube); | |
Destroy(primitive.GetComponent<Collider>()); | |
} | |
primitive.SetActive(true); | |
primitive.transform.position = hit.point; | |
} | |
} | |
else | |
if (Input.GetMouseButtonUp(0)) { | |
if (primitive != null) | |
{ | |
primitive.SetActive(false); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment