Question by
FrancisNorrie · Nov 06, 2015 at 02:28 PM ·
raycastinggamepadwiiwiimote2d-sidescroller
HELP! NEED TO BE ABLE TO CLICK MOUSE OVER AND OVER AND DO DIFFERET THINGS
using UnityEngine; using System.Collections;
public class TabletManager : MonoBehaviour {
// Varible to access TV AND GameScreen Camera
public Camera TVcamera;
public Camera GamePadCamera;
private bool[] b_mouseButtonDown;
private Vector3 v3_mousePosition;
// Varibles for Main Gamepad Buttons ( Enemy Selection, Enemy Target, Enemy Path, Number of Enemies)
private GameObject go_EnemySelectionBtn;
private GameObject go_EnemySelectionBtn1;
private GameObject go_EnemyPathBtn;
private GameObject go_EnemyTargetBtn;
private GameObject go_EnemyNumBtn;
private GameObject go_LaunchBtn;
private GameObject go_EnemySelectionBtn1Pressed;
private GameObject go_EnemySeletionBtnPressed;
private GameObject go_EnemyPathBtnPressed;
private GameObject go_EnemyTargetBtnPressed;
private GameObject go_EnemyNumBtnPressed;
private GameObject go_LaunchBtnPressed;
//Varibles for Main GamePad SubButtons ( Ships, Path, Target )
private int i_NumOfEnemies = 0;
public enum e_TabletMenuButtons { // Button States
SELECT, // Enemy Selection Btm
PATH, // Enemy Path Selection Btn
TARGET, // Enemy Target Selection Btn
NUMBER, // Number of Enemy Selection btn
LAUNCH, // Launch Btn When ready
EDIT // Edit Descission
}
public enum e_TabletScreenState{ // ScreenStates
EDIT, // Edit Choices Already made
VIEWING, // View Your attack.
PLANNING // Planning youre attack
}
public enum e_TabletGameState { // PlayStates
SINGLEPLAY, // Single player mode
COOP, //Muiltiplayer Co Op Mode
VERSES, //Muiltiplayer Verses Mode
BOSS, // Boss Battles Mode
STORY // Story / Campagin Mode.
}
public e_TabletMenuButtons e_tabletMenuButtons; // Button States
public e_TabletScreenState e_tabletScreenState; // ScreenStates
public e_TabletGameState e_tabletGameState; // PlayStates
// Use this for initialization
public void TabletStart () {
//SetButtonState (e_TabletMenuButtons.SELECT);
SetTabletScreenState (e_TabletScreenState.PLANNING);
b_mouseButtonDown = new bool[3];
for (int i = 0; i < b_mouseButtonDown.Length; i++) {
b_mouseButtonDown[i] = false;
}
TabletUpdate ();
}
public void Selection() {
go_EnemySelectionBtn = GameObject.Find ("EnemySelectionBtn");
go_EnemySeletionBtnPressed = GameObject.Find ("EnemySelectionBtnPressed");
go_EnemySelectionBtn1 = GameObject.Find ("EnemySelectionBtn1");
if (Input.GetMouseButton (0)) {
Vector2 pos = new Vector2 (Input.mousePosition.x, Input.mousePosition.y);
RaycastHit2D hit = Physics2D.Raycast (GamePadCamera.ScreenToWorldPoint (pos), Vector2.zero);
// Other Poss rays
// RaycastHit2D Hit = Physics2D.Raycast(GamePadCamera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
//Ray ray = GamePadCamera.ScreenPointToRay(Input.mousePosition);
//Ray GamePadRay;
if ( hit.collider && GameObject.Find ("EnemySelectionBtn")) {
Debug.Log ("hit selection");
go_EnemySelectionBtn.SetActive (false);
go_EnemySeletionBtnPressed.GetComponent<SpriteRenderer> ().enabled = true;
//IF RAYCAST HITS NOTHING - DO NOTHING.
}
}
return;
}
public void Target() {
go_EnemyTargetBtn = GameObject.Find ("EnemyTargetBtn");
if (Input.GetMouseButton (0)) {
Vector2 pos1 = new Vector2 (Input.mousePosition.x, Input.mousePosition.y);
RaycastHit2D hit1 = Physics2D.Raycast (GamePadCamera.ScreenToWorldPoint (pos1), Vector2.zero);
// Other Poss rays
// RaycastHit2D Hit = Physics2D.Raycast(GamePadCamera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
//Ray ray = GamePadCamera.ScreenPointToRay(Input.mousePosition);
//Ray GamePadRay;
if (hit1.collider && GameObject.Find ("EnemyTargetBtn")) {
Debug.Log ("hit target");
go_EnemyTargetBtn.SetActive (false);
//go_EnemyTargetBtnPressed.GetComponent<SpriteRenderer> ().enabled = true;
}
}
}
public void TabletButtons() {
if (Application.loadedLevelName != "GamePad") {
return;
}
}
/*
switch (e_tabletMenuButtons) {
case e_TabletMenuButtons.SELECT:
break;
case e_TabletMenuButtons.PATH:
break;
case e_TabletMenuButtons.TARGET:
break;
case e_TabletMenuButtons.NUMBER:
break;
case e_TabletMenuButtons.EDIT:
break;
case e_TabletMenuButtons.LAUNCH:
break;
}
*/
// Update is called once per frame
public void TabletUpdate () {
Selection();
Target ();
}
//**********************************************************BUTTONS****************GETTERS****************************************************************************************************************************
public bool GetMouseButton(MOUSE_BUTTON mouseButton) {
return b_mouseButtonDown[(int)mouseButton];
}
public Vector3 GetMousePosition() { return v3_mousePosition; }
private Vector3 GetWorldPos(Vector3 mousePos) {
Vector3 pos = mousePos;
pos.z = 10;
pos = Camera.main.ScreenToWorldPoint(pos);
return pos;
}
public e_TabletScreenState GetTabletScreenState(){
return e_tabletScreenState;
}
// Gets the amount of Enemies the Player wants to spawn.
//**********************************************************OTHER********************GETTERS****************************************************************************************************************************
public e_TabletMenuButtons GetButtonState(){
return e_tabletMenuButtons;
}
//*************************************************BUTTON************************SETTERS****************************************************************************************************************************\
public void SetMouseButton(MOUSE_BUTTON mouseButton, bool b_isDown) {
b_mouseButtonDown[(int)mouseButton] = b_isDown;
}
public void SetButtonState(e_TabletMenuButtons button){
e_tabletMenuButtons = button;
}
public void SetMousePosition(Vector3 newV3) { v3_mousePosition = newV3; }
//*****************************************************OTHER********************SETTERS****************************************************************************************************************************
public void SetTabletScreenState(e_TabletScreenState state){
e_tabletScreenState = state;
}
}
Comment
Your answer
Follow this Question
Related Questions
Wiimote, check IR 0 Answers
Local multiplayer New Input System 0 Answers
My Ray is going the wrong way 1 Answer