// Use this for initialization void Start() { wandTransform = CC_CANOE.WandTransform(wand); upParticles = transform.GetChild(0).gameObject; downParticles = transform.GetChild(1).gameObject; leftParticles = transform.GetChild(2).gameObject; rightParticles = transform.GetChild(3).gameObject; }
//Get the color from the color picker quad and set color to the wand's line renderer private void getColor(Wand wand) { //The line pointer origin is the Wand's world offset position. Vector3 rayOrigin = leftRayOrigin.transform.position; if (wand == Wand.Right) { rayOrigin = rightRayOrigin.transform.position; } //The line pointer direction is the Wand's transform forward direction. Vector3 rayDirection = CC_CANOE.WandTransform(wand).forward; //Draw the line pointer drawLinePointer(wand, rayOrigin, rayDirection); //Raycast stuff RaycastHit hit; Renderer rend; if (Physics.Raycast(rayOrigin, rayDirection, out hit, 30)) { if (hit.transform.gameObject.name.Equals("ColorPicker")) { rend = hit.transform.GetComponent <Renderer>(); Texture2D textureMap = rend.material.mainTexture as Texture2D; Vector2 pixelUV = hit.textureCoord; if (wand == Wand.Left) { leftColor = textureMap.GetPixelBilinear(pixelUV.x, pixelUV.y); linePointer1.startColor = leftColor; linePointer1.endColor = leftColor; line1.startColor = leftColor; line1.endColor = leftColor; } else if (wand == Wand.Right) { rightcolor = textureMap.GetPixelBilinear(pixelUV.x, pixelUV.y); linePointer2.startColor = rightcolor; linePointer2.endColor = rightcolor; line2.startColor = rightcolor; line2.endColor = rightcolor; } } } }
void LateUpdate() { if (drawWithLeft) { //Draw line for left wand. if (CC_INPUT.GetButtonPress(Wand.Left, WandButton.Down)) { //If lineCount is zero then we are starting a new line. if (lineCount1 == 0) { newLine1 = Instantiate(line1, CC_CANOE.WandTransform(Wand.Left).position, CC_CANOE.WandTransform(Wand.Right).rotation); } lineCount1++; newLine1.positionCount = lineCount1; newLine1.SetPosition(lineCount1 - 1, CC_CANOE.WandTransform(Wand.Left).position); } else { lineCount1 = 0; } //Color pick for left wand. if (CC_INPUT.GetButtonPress(Wand.Left, WandButton.Up)) { getColor(Wand.Left); } else { //Erase the line pointer. linePointer1.positionCount = 0; } } if (drawWithRight) { //Draw line for right wand. if (CC_INPUT.GetButtonPress(Wand.Right, WandButton.Down)) { //If lineCount is zero then we are starting a new line. if (lineCount2 == 0) { newLine2 = Instantiate(line2, CC_CANOE.WandTransform(Wand.Right).position, CC_CANOE.WandTransform(Wand.Right).rotation); } lineCount2++; newLine2.positionCount = lineCount2; newLine2.SetPosition(lineCount2 - 1, CC_CANOE.WandTransform(Wand.Right).position); } else { lineCount2 = 0; } //Color pick for right wand. if (CC_INPUT.GetButtonPress(Wand.Right, WandButton.Up)) { getColor(Wand.Right); } else { //Erase the line pointer. linePointer2.positionCount = 0; } } }
// Use this for initialization void Start() { wandTransform = CC_CANOE.WandTransform(wand); permanentTrail = Instantiate(projectile, projectile.transform.position, projectile.transform.rotation); }
// Update is called once per frame void Update() { Transform wandTransform = CC_CANOE.WandTransform(wand); Vector3 offset = new Vector3(wandTransform.position.x, wandTransform.position.y + verticalOffset, wandTransform.position.z); float angle = Mathf.Atan2(CC_INPUT.GetAxis(wand, WandAxis.YAxis), CC_INPUT.GetAxis(wand, WandAxis.XAxis)); if (angle < 0f) { angle += 2 * Mathf.PI; } angle = angle * (180f / Mathf.PI); if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick)) { if ((angle >= 45f) && (angle <= 135f)) { Debug.Log("Up object selected"); lanternObj = upObject; chosenButton = WandButton.Up; } else if ((angle >= 225f) && (angle <= 315f)) { Debug.Log("Down object selected"); lanternObj = downObject; chosenButton = WandButton.Down; } else if ((angle > 135f) && (angle < 225f)) { Debug.Log("Left object selected"); lanternObj = leftObject; chosenButton = WandButton.Left; } else if (((angle >= 0) && (angle < 45)) || ((angle > 315) && (angle <= 360f))) { Debug.Log("Right object selected"); lanternObj = rightObject; chosenButton = WandButton.Right; } } if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick)) { lanternObj.transform.localScale = Vector3.zero; Vector3 rotation = lanternObj.transform.eulerAngles; Quaternion quat = Quaternion.identity; lantern = Instantiate(lanternObj, offset, quat); lantern.gameObject.SetActive(true); lantern.transform.position = offset; } else if (CC_INPUT.GetButtonPress(wand, WandButton.TrackpadClick)) { lantern.transform.position = offset; } else if (CC_INPUT.GetButtonUp(wand, WandButton.TrackpadClick)) { lantern.GetComponent <Rigidbody>().isKinematic = false; lantern.GetComponent <Rigidbody>().AddForce(new Vector3(0, releaseForce, 0)); lantern.GetComponent <Lantern>().startExpiring = true; } }