又是忙碌的一天,但是“始终坚持,学有渐长。深夜博客,已成习惯”,又到了深夜CSDN时间了今天我遇到了一些问题有些解决了有些没解决。以下是我个人的一些个人理解。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColumnController : MonoBehaviour
{
public GameObject columnPrefab;
public int columnMax = 5;
public float spawnRate = 3f;
public float yMin = -1f;
public float yMax = 3.5f;
public float xPos = 10f;
float timeSinceLastSpawned;
GameObject[] colums;
int currentColumn = 0;
Vector2 originalPos = new Vector2(-10, -20);
void Start ()
{
colums = new GameObject[columnMax];
for(int i = 0; i < columnMax; i++)
{
colums[i] = Instantiate(columnPrefab, originalPos, Quaternion.identity);
}
}
void Update ()
{
timeSinceLastSpawned += Time.deltaTime;
if (GameMode.instance.gameOver == false && timeSinceLastSpawned >= spawnRate)
{
timeSinceLastSpawned = 0f;
float yPos = Random.Range(yMin, yMax);
colums[currentColumn].transform.position = new Vector2(xPos, yPos);
currentColumn++;
if(currentColumn >= columnMax)
{
currentColumn = 0;
}
}
}
}
这是我前些天所打一些代码,没错这是一些游戏代码是关于一款2D升降机的游戏,今天要感谢学长帮助了我解决问题,这是我修改后的代码,这是关于障碍物在画面背景不断生成的代码,我的问题是在unity3d中的scene与Game的景色不协调并且scene与game不一致,解决方法是调整z轴的值归零,原因是相机并未归于零轴,但是由于柱子是随机生成的导致了柱子并非诞生在画面上,再加上相机偏差导致其出现偏差。
其实最大的问题是,如果有此类问题,制作者往往会以为是生成函数或者rigidbody调试出现问题,忽略了细小问题总是让人摸不着头脑。由于明天也是忙碌的所以只能到此为止了。明天再来。