// Update is called once per frame void Update() { Debug.DrawRay(transform.position, worldPos - transform.position, Color.green); // linkToTrackingPosition(); SkinnedGUIOptions guiOptions = GetComponent <SkinnedGUIOptions>(); if (Input.GetMouseButtonDown(0) && guiOptions.returnModeValue() == 0) { Vector2 mousePos = Input.mousePosition; float fwd = 10; Vector3 mPos = new Vector3(mousePos.x, mousePos.y, fwd); worldPos = main.ScreenToWorldPoint(mPos); if (Physics.Raycast(transform.position, worldPos - transform.position, fwd)) { //print("There is something in front of the object!"); Debug.DrawRay(transform.position, worldPos); } RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.collider != null) { Vector3 hitPoint = hit.point; int closestVertice = indexClosestVertice(hitPoint); //vertexPos is the closest Vertice to collision point Vector3 fbxPos = vertices[closestVertice] + rootGuy.transform.position; // * SCALING GameObject newVertice = GameObject.Instantiate(vertice); //newVertice.transform.position = vertexPos; //print("closest Vertice "+closestVertice+" indexLinks Count"+indexLinks.Count); //Vector3 fbxPos = fbxMesh.vertices[indexVertice]; print(fbxGuy.transform.localScale.x); //newVertice.transform.position = fbxPos * fbxGuy.transform.localScale.x; newVertice.transform.position = fbxPos; MeshRenderer mrv = newVertice.GetComponent <MeshRenderer>(); mrv.material = guiOptions.returnOpacityMaterial(); mrv.material.color = guiOptions.returnPowerColor(); if (!trackingIndexesContains(indexLinks[closestVertice])) { trackingPointsGameObjects.Add(newVertice); //trackingIndexes.Add(closestVertice); trackingStrengths.Add(guiOptions.returnPower()); trackingIndexes.Add(indexLinks[closestVertice]); GameObject newHitPoint = GameObject.Instantiate(myHitPoint); newHitPoint.transform.position = hitPoint; } } } } if (Input.GetKeyDown(KeyCode.Delete)) { removeTrackingPoints(false); } if (Input.GetKeyDown(KeyCode.Z)) { removeTrackingPoints(true); //removeLastIndexLink(); } }
// Update is called once per frame void Update() { Debug.DrawRay(transform.position, worldPos - transform.position, Color.green); // linkToTrackingPosition(); SkinnedGUIOptions guiOptions = GetComponent <SkinnedGUIOptions>(); if (Input.GetMouseButtonDown(0) && guiOptions.returnModeValue() == 0) { Camera main = transform.GetComponent <Camera>(); Vector2 mousePos = Input.mousePosition; float fwd = 10; Vector3 mPos = new Vector3(mousePos.x, mousePos.y, fwd); worldPos = main.ScreenToWorldPoint(mPos); RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.collider != null) { Vector3 hitPoint = hit.point; int closestVertice = indexClosestVertice(hitPoint); Vector3 fbxPos = vertices[closestVertice] + rootGuy.transform.position; print("WE HIT ( index closest is " + closestVertice); if (!trackingIndexesContains(closestVertice)) { GameObject newVertice = GameObject.Instantiate(vertice); newVertice.transform.position = fbxPos; // MODIFIEE // trackingPoints.Add(new TrackingPoint(newVertice, indexLinks[closestVertice], guiOptions.returnPower())); trackingPoints.Add(new TrackingPoint(newVertice, closestVertice, guiOptions.returnPower())); GameObject newHitPoint = GameObject.Instantiate(myHitPoint); newHitPoint.transform.position = hitPoint; MeshRenderer mrv = newVertice.GetComponent <MeshRenderer>(); mrv.material = guiOptions.returnOpacityMaterial(); mrv.material.color = guiOptions.returnPowerColor(); } else { if (Input.GetKey(KeyCode.LeftShift)) { removeTrackingPoint(closestVertice); } } /* * } * else * { * * * * print("out"); * * GameObject newVertice = GameObject.Instantiate(vertice); * newVertice.transform.position = fbxPos;// MODIFIEE * * GameObject newHitPoint = GameObject.Instantiate(myHitPoint); * newHitPoint.transform.position = hitPoint; * * } * * */ } } } if (Input.GetKeyDown(KeyCode.Delete)) { removeTrackingPoints(false); } if (Input.GetKeyDown(KeyCode.Z)) { removeTrackingPoints(true); } }