- Home /
Question by
parkgirim215 · Jun 04 at 03:08 PM ·
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