private Vector2 bgImageStartPosition; // used to temporarily store the starting position of the joystick's background image (where it was placed on the canvas in the editor before play was pressed) in order to set the image back to this same position after setting the pivot to the bottom right corner of the image private void Start() { _s = this; if (GetComponent <Image>() == null) { Debug.LogError("There is no joystick image attached to this script."); } if (transform.GetChild(0).GetComponent <Image>() == null) { Debug.LogError("There is no joystick handle image attached to this script."); } if (GetComponent <Image>() != null && transform.GetChild(0).GetComponent <Image>() != null) { bgImage = GetComponent <Image>(); // gets the background image of this joystick joystickKnobImage = transform.GetChild(0).GetComponent <Image>(); // gets the joystick "knob" imae (the handle of the joystick), the joystick knob game object must be a child of this game object and have an image component bgImage.rectTransform.SetAsLastSibling(); // ensures that this joystick will always render on top of other UI elements bgImage.rectTransform.GetWorldCorners(fourCornersArray); // fills the fourCornersArray with the world space positions of the four corners of the background image of this joystick bgImageStartPosition = fourCornersArray[3]; // saves the world space position of the bottom right hand corner of the background image of this joystick as the image was placed on the canvas before play was pressed bgImage.rectTransform.pivot = new Vector2(1, 0); // places the bottom right corner of background image of this joystick onto the pivot (wherever it may be in the canvas) //bgImage.rectTransform.anchorMin = new Vector2(0, 0); // sets the min anchors to the lower left corner of the canvas //bgImage.rectTransform.anchorMax = new Vector2(0, 0); // sets the max anchors to the lower left corner of the canvas bgImage.rectTransform.position = bgImageStartPosition; // sets the background image of this joystick back to the same position it was on the canvas before play was pressed } }
private void Awake() { if (Instance == null) { Instance = this; } else { Destroy(gameObject); } }
// Use this for initialization void Start() { hasDied = false; spr = gameObject.GetComponent <SpriteRenderer>(); if (!hasSaved) { initPos = gameObject.transform.position; startPos = initPos; } else if (SceneManager.GetActiveScene().name == "SampleScene") { gameObject.transform.position = startPos; } singleJoyStick = FindObjectOfType <SingleJoystick>(); jumpBtn = FindObjectOfType <JumpBtn>(); PA = gameObject.GetComponent <PlayerAnimation>(); }
private void Start() { if (this.singleJoystickBackgroundImage.GetComponent <SingleJoystick>() == null) { Debug.LogError("There is no joystick attached to this script."); } else { this.singleJoystick = this.singleJoystickBackgroundImage.GetComponent <SingleJoystick>(); this.singleJoystickBackgroundImage.enabled = this.singleJoyStickAlwaysVisible; } if (this.singleJoystick.transform.GetChild(0).GetComponent <Image>() == null) { Debug.LogError("There is no joystick handle (knob) attached to this script."); } else { this.singleJoystickHandleImage = this.singleJoystick.transform.GetChild(0).GetComponent <Image>(); this.singleJoystickHandleImage.enabled = this.singleJoyStickAlwaysVisible; } }
private int singleSideFingerID = 0; // unique finger id for touches on the left-side half of the screen void Start() { if (singleJoystickBackgroundImage.GetComponent <SingleJoystick>() == null) { Debug.LogError("There is no joystick attached to this script."); } else { singleJoystick = singleJoystickBackgroundImage.GetComponent <SingleJoystick>(); // gets the single joystick script singleJoystickBackgroundImage.enabled = singleJoyStickAlwaysVisible; // sets single joystick background image to be always visible or not } if (singleJoystick.transform.GetChild(0).GetComponent <Image>() == null) { Debug.LogError("There is no joystick handle (knob) attached to this script."); } else { singleJoystickHandleImage = singleJoystick.transform.GetChild(0).GetComponent <Image>(); // gets the handle (knob) image of the single joystick singleJoystickHandleImage.enabled = singleJoyStickAlwaysVisible; // sets single joystick handle (knob) image to be always visible or not } }
protected virtual void Start() { CharacterInit(); _singleJoystick = FindObjectOfType <SingleJoystick>(); }