Quantcast
Viewing all articles
Browse latest Browse all 120

Trouble Swapping GameObjects on a Game Pad That are Prefabs.

Hi everyone, I am having a little trouble in making my gameobjects change from any position on my game pad. ---------- I have a script that works great for gameobjects, however, it does not work in my game on items that are know as (Chips). The game acts like the script is not there and there are no error codes. ---------- Here is the code that I am using to test this system out: ---------- using System.Collections; using System.Collections.Generic; using System.Linq; using Berry.Utils; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class DragSwitch : MonoBehaviour { public const string DRAGGABLE_TAG = "Draggable"; private bool dragging = false; private Vector2 originalPosition; private Transform objectToDrag; private Image objectToDragImage; List hitObjects = new List(); #region Monobehaviour API void Update () { if (Input.GetMouseButtonDown(0)) { objectToDrag = GetDraggableTransformUnderMouse(); if (objectToDrag != null) { dragging = true; objectToDrag.SetAsLastSibling(); originalPosition = objectToDrag.position; objectToDragImage = objectToDrag.GetComponentImage may be NSFW.
Clik here to view.
(); objectToDragImage.raycastTarget = false; } } if (dragging) { objectToDrag.position = Input.mousePosition; } if (Input.GetMouseButtonUp(0)) { if (objectToDrag != null) { var objectToReplace = GetDraggableTransformUnderMouse(); if (objectToReplace != null) { objectToDrag.position = objectToReplace.position; objectToReplace.position = originalPosition; } else { objectToDrag.position = originalPosition; } objectToDragImage.raycastTarget = true; objectToDrag = null; } dragging = false; } } private GameObject GetObjectUnderMouse() { var pointer = new PointerEventData(EventSystem.current); pointer.position = Input.mousePosition; EventSystem.current.RaycastAll(pointer, hitObjects); if (hitObjects.Count <= 0) return null; return hitObjects.First().gameObject; } private Transform GetDraggableTransformUnderMouse() { var clickedObject = GetObjectUnderMouse(); // get top level object hit if (clickedObject != null && clickedObject.tag == DRAGGABLE_TAG) { return clickedObject.transform; } return null; } #endregion } ---------- Let me know if you have any ideas how to make gameobjects that are in prefabs and only shown during game play on a game pad. The script calls for the gameobject to be tagged, which I tagged them to the calling of Draggable, and nothing seems to work.

Viewing all articles
Browse latest Browse all 120

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>