加载新场景时,我遇到了鼠标拖动无法转移到下一个场景并且在加载新场景时必须重新单击的麻烦。
我希望鼠标点击可以无缝地转移到下一个场景而不会引起玩家的注意,更一般地说,我想知道如何最好地保留某些游戏对象并使它们转移到下一个场景。
从本质上讲,我想要做的是让整个游戏表现得像一个大场景,玩家可以玩这个大场景,但仍然可以分解成更小的场景,这些场景可以在后期访问或转换成关卡。
提前致谢。
这是我目前使用的代码
using UnityEngine;
using System.Collections;
using UnityEngine.Profiling;
public class MoveBall : MonoBehaviour
{
public static Vector2 mousePos = new Vector2();
private void OnMouseDrag()
{
mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = mousePos;
DontDestroyOnLoad(this.gameObject);
}
}
Run Code Online (Sandbox Code Playgroud)
Bellow 是负责加载场景的脚本:
public class StarCollision : MonoBehaviour
{
private bool alreadyScored = false;
private void OnEnable()
{
alreadyScored = false;
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("White Ball"))
{
if (!alreadyScored)
{
ScoreScript.scoreValue += 1;
StartCoroutine(ChangeColor());
alreadyScored = true;
}
}
if …Run Code Online (Sandbox Code Playgroud) 我目前正在 Unity 中制作一款游戏,其中我试图仅在预制件的克隆离开相机视图后才销毁它们,只有在它们首先进入相机视图后才销毁它们。然而,由于某种原因,我的代码在克隆实例化后立即销毁它们。有谁知道我该如何解决这个问题?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InteractControl : MonoBehaviour
{
Rigidbody2D rb;
GameObject target;
float moveSpeed;
Vector3 directionToTarget;
// Use this for initialization
void Start()
{
target = GameObject.Find("White Ball");
rb = GetComponent<Rigidbody2D>();
moveSpeed = 3f;
}
// Update is called once per frame
void Update()
{
MoveInteract();
OnBecameVisible();
}
/*void OnTriggerEnter2D(Collider2D col)
{
switch (col.gameObject.tag)
{
case "ColouredBall Highress":
BallSpawnerControl.spawnAllowed = false;
Destroy(gameObject);
target = null;
break;
case "Star":
Collision collision = new Collision(); …Run Code Online (Sandbox Code Playgroud)