/* * private Vector3 parentchildRotationVector() * { * return new Vector3 (parentTransformX.transform.rotation.eulerAngles[0], transform [1], 0); * } */ void cursorHitTest() { // Debug.Log ("cursorHitTest"); //int x = Screen.width / 2; //int y = Screen.height / 2; Vector3 gPos = aim_sprite.GetComponent <RectTransform>().position; // Debug.Log ("aim_sprite.position = " +gPos); //Vector2 convertedGUIPos = GUIUtility.GUIToScreenPoint(gPos); //Ray ray = camera.ScreenPointToRay(new Vector3(x, y)); Ray ray = Camera.main.ScreenPointToRay(gPos); //Ray ray = Camera.main.ScreenPointToRay(filteredscreenSpace); RaycastHit hit; if (Physics.Raycast(ray, out hit, 500.0F)) { if (hit.collider != null) { //GameObject.Find ("Sphere").transform.position = hit.point; ballBehaviour b = hit.collider.gameObject.GetComponent <ballBehaviour>(); //.hit(); if (b != null) { // Debug.Log ("Target Position: " + hit.collider.gameObject.transform.position); b.hit(); } } } // Debug.DrawRay(ray.origin, ray.direction * 1000, new Color(1f,0.922f,0.016f,1f)); }
void instatiateBall() {//Vector3 size = spawnBox.collider.bounds; //Vector3 SpawnOrigin = spawnBox.transform.position; // zpos = 0; //Vector3 pos = spawnBallinBox(); Vector3 pos = spawnBallInArc(); currentBall = Instantiate(target_prefab, pos, Quaternion.identity) as GameObject; currentBall.transform.parent = spawnBox.transform; ballBehaviour ballbehaveScript = currentBall.GetComponent<ballBehaviour>(); ballbehaveScript.setReciever (this); ballbehaveScript.maxTime = Random.Range (minTime,maxTime); ballbehaveScript.startTheCount(); }
// if bullet collides with another object void OnTriggerEnter(Collider other) { // check if the other object is a ball (or specifically if it has the ball-behaviour attached to it ballBehaviour ball = other.GetComponent <ballBehaviour> (); //if it does if (ball != null) { // tell the ball to explode ball.Explode(); } if (other.tag != "Player") { // either way; destroy the bullet Destroy(this.gameObject); } }