void Shot() { //...setting shoot direction Vector3 shootDirection; shootDirection = Input.mousePosition; shootDirection.z = 0.0f; shootDirection = Camera.main.ScreenToWorldPoint(shootDirection); shootDirection = shootDirection - transform.position; //...instantiating the rocket GameObject bulletGO = (GameObject)Instantiate( bulletPrefab, bulletSpawn.position, bulletSpawn.rotation); CannonBall bullet = bulletGO.GetComponent <CannonBall>(); bullet.setDir(shootDirection.normalized); }