public void GrabSymbol() { print("grabbing symbol"); if (!GameObject.Find("RightController").GetComponentInChildren <SphereCollider>().gameObject.GetComponent <PassCollision>()) { PassCollision pc = GameObject.Find("RightController").GetComponentInChildren <SphereCollider>().gameObject.AddComponent <PassCollision>() as PassCollision; pointerend = pc.gameObject; } //StartCoroutine(GetSymbol()); collidingObject = FindSymbol(); if (collidingObject.CompareTag("PuzzleSymbol") || collidingObject.CompareTag("CorrectSymbol")) { if (collidingObject.GetComponent <Rigidbody>() != null) { if (collidingObject.GetComponent <Rigidbody>().isKinematic) { collidingObject.GetComponent <Rigidbody>().isKinematic = false; } } else { collidingObject.AddComponent <Rigidbody>(); collidingObject.GetComponent <Rigidbody>().isKinematic = false; } lastSymbol = collidingObject; holdingObject = true; lastSymbol.GetComponent <Rigidbody>().useGravity = false; //objectInHand.transform.SetParent(gameObject.transform); //objectInHand.GetComponent<Rigidbody>().isKinematic = true; CheckSymbol.inHand = true; collidingObject = null; var joint = AddSymbolJoint(); joint.connectedBody = lastSymbol.GetComponent <Rigidbody>(); //Vector3 worldPos = pointerend.gameObject.transform.position; // screenPos = Camera.main.WorldToScreenPoint(worldPos); // canvasPos = new Vector3(screenPos.x - Camera.main.pixelWidth / 2, screenPos.y - Camera.main.pixelHeight / 2, lastSymbol.transform.localPosition.z); // lastSymbol.transform.localPosition = canvasPos; symbolIsGrabbed = true; //Vector3 temp = Input.mousePosition; //temp.z = GameObject.Find("puzzleone").transform.position.z; // Set this to be the distance you want the object to be placed in front of the camera. //lastSymbol.transform.position = Camera.main.WorldToScreenPoint(temp); //objectInHand.transform.SetParent(gameObject.transform); //objectInHand.transform.localRotation = new Quaternion(gameObject.transform.localRotation.x, gameObject.transform.localRotation.y, gameObject.transform.localRotation.z, gameObject.transform.localRotation.w); //objectInHand.transform.position = new Vector3(gameObject.transform.Find("Model").transform.position.x, gameObject.transform.Find("Model").transform.position.y, gameObject.transform.Find("Model").transform.position.z); //gameObject.transform.Find("Model").gameObject.SetActive(false); } print("Symbol Grabbed"); }
void Update() { if (InputManager.getButtonUp(InputManager.Button.TOGGLE_WEAPONS)) { armed = !armed; } //Cycle through pylons if (InputManager.getButtonUp(InputManager.Button.WEAPON_LEFT)) { activePylon--; } if (InputManager.getButtonUp(InputManager.Button.WEAPON_RIGHT)) { activePylon++; } //Loop around if (activePylon < 0) { activePylon = pylons.Length - 1; } if (activePylon >= pylons.Length) { activePylon = 0; } //Fire pylon payload if (InputManager.getButtonUp(InputManager.Button.FIRE) && armed) { pylons [activePylon].Fire(); } //Fire guns if (InputManager.getButton(InputManager.Button.FIRE_CANNON) && armed) { //Create raycast RaycastHit hit; Physics.Raycast(gun.transform.position, transform.right, out hit, 1000); //If the bullet hits if (hit.transform != null) { print(hit.collider.name); //Create hit particles Instantiate(bulletHit, hit.point, new Quaternion(0, 0, 0, 0)); //If there is a passCollision script attached, call Shot() PassCollision hitPart = hit.collider.gameObject.GetComponent <PassCollision> (); if (hitPart != null) { hitPart.Shot(damage); } } Debug.DrawRay(gun.transform.position, transform.right * 1000); } ///Set Instrument panel data panel.SetWeaponData(pylons [activePylon].ammo, pylons [activePylon].type, armed); }