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 /
avatar image
0
Question by freemann098 · Feb 17, 2016 at 09:07 PM · build3dwindowsdrag objects

Dragging Objects Breaks after Building game

The game I'm working on has a mechanic where you can drag around objects in the room. This game and everything in it works in the Unity Editor but not when I build the game for Windows. In the build, you can't drag any objects or anything. This game does support Oculus Rift but I'm not sure if that has anything to do with especially because the game worked perfectly fine before my newest update. I have attempted to look through code and such to see what I've changed and tried switching things backward but it still breaks.

The script used for dragging objects around. using UnityEngine; using UnityEngine.UI; using System.Collections;

 public class CameraScript : MonoBehaviour
 {
     bool objectGrabbed = false;
     public static GameObject currentObject;
     public static bool dropped = true;
     public GameObject currentChild;
     public GameObject targetTransform;
     public Image crosshair;
     public float objectDistance;
     public int magnetism;
     public float dampening;
     public float deadRange;
 
     // Use this for initialization
     void Start()
     {
 
     }
 
     // Update is called once per frame
     void Update()
     {
         Ray cameraRay = new Ray(transform.position, transform.forward);
         RaycastHit camHit;
         Debug.DrawRay(transform.position, transform.forward);
 
         if (Physics.Raycast(cameraRay, out camHit) && camHit.collider.gameObject.tag == "Interactable" && LetterManager.canMoveAnything == true)
         {
             crosshair.color = Color.green;
             if (Input.GetAxis("Fire1") != 0 && currentObject == null)
             {
                 dropped = false;
                 objectGrabbed = true;
                 SetCurrentObject(camHit.collider.gameObject);
             }
         }
         else if (currentObject == null)
         {
             crosshair.color = Color.white;
             objectGrabbed = false;
         }
 
         //drops object
         if (Input.GetAxis("Fire1") == 0 && currentObject != null)
         {
             dropped = true;
             SetCurrentObject(null);
         }
 
         if (Physics.Raycast(cameraRay, out camHit) && Input.GetButtonDown("Fire2"))
         {
             camHit.collider.gameObject.GetComponent<Activatable>().Activate();
         }
 
 
         objectDistance = objectDistance + Input.GetAxis("Mouse ScrollWheel");
 
         if (objectGrabbed)
         {
             currentObject.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
 
             targetTransform.transform.position = new Vector3(Mathf.Sin((180 - transform.rotation.eulerAngles.y) * Mathf.Deg2Rad) * objectDistance + transform.parent.transform.position.x, Mathf.Cos((90 + transform.rotation.eulerAngles.x) * Mathf.Deg2Rad) * objectDistance + transform.parent.transform.position.y, Mathf.Cos(transform.rotation.eulerAngles.y * Mathf.Deg2Rad) * objectDistance + transform.parent.transform.position.z);
             currentChild.transform.LookAt(targetTransform.transform);
 
 
             currentObject.GetComponent<Rigidbody>().AddForce(-currentObject.GetComponent<Rigidbody>().velocity * dampening);
 
             if (Vector3.Distance(currentObject.transform.position, targetTransform.transform.position) > deadRange)
             {
                 currentObject.GetComponent<Rigidbody>().AddForce(currentChild.transform.forward * magnetism);
             }
         }
         
 
     }
 
     void SetCurrentObject(GameObject thing)
     {
         if (thing != null)
         {
             currentObject = thing;
             currentObject.GetComponent<Rigidbody>().useGravity = false;
         }
         else
         {
             currentObject.GetComponent<Rigidbody>().useGravity = true;
             currentObject = thing;
         }
 
         currentChild.transform.parent = thing.transform;
         currentChild.transform.localPosition = Vector3.zero;
 
         objectDistance = Vector3.Distance(this.gameObject.transform.position, currentObject.transform.position);
     }
 }
 
Comment
Add comment · Show 4
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
avatar image Firedan1176 · Feb 17, 2016 at 09:14 PM 0
Share

You need to post code! I can't help if I don't see what is specifically causing the problem. Can you post your code?

avatar image freemann098 Firedan1176 · Feb 17, 2016 at 09:24 PM 0
Share

I added the script but my problem is I didn't really even edit this code before it broke, so I don't believe it has anything to do with this script. Another guess I have is tags, every movable object is tagged "Interactable" and when I'm in the editor, the Interactable tag is completely gone and every GameObject with that tag now has Undefined as their tags until I play the game and they all go back to Interactable.

avatar image Firedan1176 freemann098 · Feb 17, 2016 at 09:27 PM 0
Share

What version of Unity are you using? 5.3.1f1? There's bugs, I'd try another version.

Show more comments

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

37 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

dll doesn't work after build 0 Answers

How to fix Unity compiler error when building WP8.1 game? 2 Answers

Application reduced in task bar. force focus on app, always on top 0 Answers

Unity UWP build open only a white screen 2 Answers


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