public void CreateUnit(Color32 color) { GameObject go = new GameObject(); UnitGroup ug = go.AddComponent <UnitGroup>(); ug.color = color; _dropdown.SetActiveUnit(go, false); }
// Update is called once per frame void Update() { if (!_texture) { _texture = videoRenderer.getWebCamTexture(); // Debug.Log(_texture.width); } if (Input.GetMouseButtonDown(1)) { RaycastHit hit; MeshCollider collie = videoRenderer.gameObject.GetComponentInChildren <MeshCollider>(); if (!collie.Raycast(Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z)), out hit, 2000f)) { return; } Renderer rend = hit.transform.GetComponent <Renderer>(); MeshCollider meshCollider = hit.collider as MeshCollider; if (rend == null || meshCollider == null) { return; } Vector2 pixelUV = hit.textureCoord; pixelUV.x *= 1280f; pixelUV.y *= 720f; Color32 color = (Color32)_texture.GetPixel((int)pixelUV.x, (int)pixelUV.y); ctp.colorTargets.Add(new Vexpot.ColorTarget(color, tolerance)); ctp.StopColorTracker(); ctp.UpdateColorTargets(); ctp.StartColorTracker(); _factory.CreateUnit(color); _constructor.ColorSelected(color); } if (Input.GetMouseButtonDown(0)) { UnitGroup ug = null; if (_gManager.GetGridUnit(_gManager.GetGridPos(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0))) != null) { ug = _gManager.GetGridUnit(_gManager.GetGridPos(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0))); } if (ug != null) { _constructor.SetActiveUnit(ug.gameObject, true); _logController.updateStats(ug.info); } } }