// Use this for initialization void Start() { // get players, joystick, InGame and Blob players = GameObject.FindGameObjectsWithTag("PlayerTeam1"); oponents = GameObject.FindGameObjectsWithTag("OponentTeam"); joystick = GameObject.FindGameObjectWithTag("joystick").GetComponent <Joystick_Script>(); inGame = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <InGameState_Script>(); blobPlayerSelected = GameObject.FindGameObjectWithTag("PlayerSelected").transform; }
private void Awake() { gui = GetComponent <GUITexture>(); if (gui.texture == null) { Debug.LogError("Joystick object requires a valid texture!"); gameObject.SetActive(false); return; } if (!enumeratedJoysticks) { try { /* Collect all joysticks in the game, so we can relay finger latching messages */ GameObject[] objs = GameObject.FindGameObjectsWithTag(joysticksTag); joysticks = new List <Joystick_Script>(objs.Length); foreach (GameObject obj in objs) { Joystick_Script newJoystick = obj.GetComponent <Joystick_Script>(); if (newJoystick == null) { throw new NullReferenceException("Joystick gameObject found without a suitable Joystick component."); } joysticks.Add(newJoystick); } enumeratedJoysticks = true; } catch (Exception exp) { Debug.LogError("Error collecting Joystick objects: " + exp.Message); throw; } } /* Store the default rect for the gui, so we can snap back to it */ defaultRect = gui.pixelInset; defaultRect.x += transform.position.x * Screen.width; // + gui.pixelInset.x; // - Screen.width * 0.5f; defaultRect.y += transform.position.y * Screen.height; // - Screen.height * 0.5f; transform.position = new Vector3(0, 0, transform.position.z); if (touchPad) { /* Use the rect from the gui as our touchZone */ touchZone = defaultRect; } else { /* This is an offset for touch input to match with the top left corner of the GUI */ guiTouchOffset.x = defaultRect.width * 0.5f; guiTouchOffset.y = defaultRect.height * 0.5f; /* Cache the center of the GUI, since it doesn't change */ guiCenter.x = defaultRect.x + guiTouchOffset.x; guiCenter.y = defaultRect.y + guiTouchOffset.y; /* Let's build the GUI boundary, so we can clamp joystick movement */ guiBoundary.min.x = defaultRect.x - guiTouchOffset.x; guiBoundary.max.x = defaultRect.x + guiTouchOffset.x; guiBoundary.min.y = defaultRect.y - guiTouchOffset.y; guiBoundary.max.y = defaultRect.y + guiTouchOffset.y; } }