• 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 parkgirim215 · 6 days ago · raycastwindowsbuild and run

When I build a project, objects in a scene using Raycast are superimposed and loaded in a clicked state.

 using System.Collections;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class WritingReport_RayCast : MonoBehaviour
 {
     GameObject done;
     float distance = 15f;
     int num;
     int maxNum; // 4문장 기준
     string hittedTag;
     bool stext = false; //  선택text 활성화 여부
     bool already = false;   //  선택text 활성화 한 번만 하도록
     GameObject curParent;
     RaycastHit2D hit;
     string path;
 
     Vector3 position;
     Camera cam;
 
 
     void Start()
     {
         num = 0;
         maxNum = 3;
 
         done = GameObject.Find("완료");
         cam = GetComponent<Camera>();
     }
 
 
     //  부모tag > 유도텍스트=0, 빈칸텍스트=1, 선택텍스트=2
     void Update()
     {
         //  유도text, 선택text 활성화
         if (!stext && !already && num<maxNum)
         {
             curParent = GameObject.Find("유도텍스트" + (num + 1).ToString());
             curParent.transform.GetChild(0).gameObject.SetActive(true);
 
             curParent = GameObject.FindGameObjectsWithTag(num.ToString())[1];
             for (int i = 0; i < 4; i++)
             {
                 curParent.transform.GetChild(i).gameObject.SetActive(true);
             }
             stext = true;
             already = true;
         }
         
         //  클릭시 ray() 실행
         if(Input.GetMouseButtonDown(0))
         {
             if (Input.mousePosition != null) position = Input.mousePosition;
             position = cam.ScreenToWorldPoint(position);
 
             hit = Physics2D.Raycast(position, transform.forward, distance);
             
             Debug.DrawRay(position, transform.forward * 500, Color.red, 0.3f);
 
             if (hit && hit.collider.gameObject.tag == "Finish")
             {
                 StartCoroutine(Rendering());
                 StartCoroutine(LoadMyAsyncScene());
             }
             else if (hit && hit.collider.gameObject.tag != "Untagged")
             {
                 Ray(ref hit, ref num);
                 already = false;
             }
       }
  }
 
 
     void Ray(ref RaycastHit2D hit, ref int num)
     {
         hittedTag = hit.collider.gameObject.tag;
 
         //  빈칸text 선택에 맞게 활성화
         curParent = GameObject.FindGameObjectsWithTag(num.ToString())[0];
         if (hittedTag=="choice1")
             curParent.transform.GetChild(0).gameObject.SetActive(true);  
         else if (hittedTag=="choice2")
             curParent.transform.GetChild(1).gameObject.SetActive(true);
         else if (hittedTag=="choice3")
             curParent.transform.GetChild(2).gameObject.SetActive(true);
         else
             curParent.transform.GetChild(3).gameObject.SetActive(true);
 
         hittedTag = "";
 
         //  선택text 비활성화
         curParent = GameObject.FindGameObjectsWithTag(num.ToString())[1];
         for (int i = 0; i < 4; i++)
         {
             curParent.transform.GetChild(i).gameObject.SetActive(false);
         }
         stext = false;
         num++;
         Debug.Log(num);
 
         if (num == maxNum)
         {
             curParent = GameObject.Find("유도텍스트" + (num + 1).ToString());
             curParent.transform.GetChild(0).gameObject.SetActive(true);
             curParent.transform.GetChild(1).gameObject.SetActive(true);
 
             done.GetComponent<SpriteRenderer>().enabled = true;
             done.GetComponent<BoxCollider2D>().enabled = true;
             num++;
         }
         else
         {
             curParent = GameObject.FindGameObjectsWithTag(num.ToString())[0];
             for (int i = 0; i < 4; i++)
             {
                 curParent.transform.GetChild(i).gameObject.SetActive(false);
             }
         }
     }
 
     IEnumerator LoadMyAsyncScene()
     {
         yield return new WaitForSeconds(1.0f);
 
 
         PlayerPrefs.SetString("path", path);
         AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("BookReportScene");
         
         while (!asyncLoad.isDone)
         {
             yield return null;
         }
         
     }
 }


I made four scenes using raycasts, and I made one original and the rest copied the objects exactly as they were.

It all worked well in Unity, but after building in a Windows environment, there is a problem. In the scene, only one of the four objects that should have been clicked were loaded with all four clicked. Weirdly enough, one of the four scenes works normally. The normal scene is not the original.

I tried to create a new scene by copying the object of the normal scene as it is, but the new scene is not working properly either. I built and ran only the scene in question just in case there was a problem with loading the scene, but the problem remained the same. I'd like to ask because I don't understand at all. Please help me.

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

197 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 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 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 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 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 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

Window info not updating when moved 0 Answers

WebGL build size is much smaller compared to PC build size 0 Answers

[UWP & Device Portal] Deployment failed - Must specify an appx file to install 0 Answers

raycast rigidbody addforce 2 Answers

Why sometimes, when build, the logo of the game is unity Logo 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