Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Wiimote, check IR 0 Answers

Trying to get my generic gamepad from logitech to connect with unity. I went to input but keep getting confused with the layout. We have cross hairs in our game, but I cant seem to control them, only with the mouse? 0 Answers

Local multiplayer New Input System 0 Answers

My Ray is going the wrong way 1 Answer

how to stop when two cubes are there... 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges