私はヒルクライムのようなランナーゲームを作成しますが、ジグザグパスの表面にコインを生成する方法はわかりません。 これは私のパスです Unity:実行時にy軸を得る方法ジグザグパス
ランダムに生成されます。しかし、実行時にパス内のyの位置を取得する方法は、ランダムな位置にコインが生成されたときにコインがパスよりも若干時間を下回るためです。
実行時にパスの位置を取得して、表面にコインを生成する方法を教えてください。
パス生成コードはこれまたコインです。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TerrainGenerator : MonoBehaviour {
public chunk previousChunk;
public chunk currentChunk;
public chunk nextChunk;
public ManagePower power;
public GameObject character;
public Resize resize;
public Coin coin;
private PickupResize rise;
private pickupPower pick;
private PickupCoin pCoin;
// Use this for initialization
void Start() {
rise=FindObjectOfType<PickupResize>();
pick=FindObjectOfType<pickupPower>();
pCoin=FindObjectOfType<PickupCoin>();
float widthprefabs = previousChunk.WidthGroundPrefab;
previousChunk.RepositionChunk (new Vector3(-widthprefabs*chunk.CHUNK_SIZE,0,0));
currentChunk.RepositionChunk (Vector3.zero);
nextChunk.RepositionChunk (new Vector3(widthprefabs*chunk.CHUNK_SIZE,0,0));
power.RepositionPower (new Vector3(widthprefabs*chunk.CHUNK_SIZE,-0.1f,0));
resize.ResizeSquire (new Vector3(25f,-0.1f,0));
coin.ResetCoin (new Vector3(5f,-0.17f,0));
}
// Update is called once per frame
void Update() {
if(playerReachedNextChunk()){
reassineChunk();
}
if (rise.rePick) {
resize.ResizeSquire(new Vector3 (rise.distancere, -0.1f, 0));
rise.rePick=false;
}
if (pick.poPick) {
power.RepositionPower (new Vector3 (pick.powerdist, -0.1f, 0));
pick.poPick=false;
}
if (pCoin.distancere < ObjectScript.distance) {
int random = Random.Range (1, 10);
pCoin.distancere += random;
pCoin.reCoin = true;
}
if (pCoin.reCoin) {
coin.ResetCoin (new Vector3 (pCoin.distancere, -0.1f, 0));
pCoin.reCoin=false;
}
//print ("ddhdhdhdhhd"+ObjectScript.distance);
}
private bool playerReachedNextChunk(){
bool playerReachedNextChunk = false;
float distance = character.transform.position.x - nextChunk.transform.position.x;
//print ("Distance " +distance);
if (distance > 0) {
playerReachedNextChunk=true;
}
return playerReachedNextChunk;
}
private void reassineChunk(){
chunk refToprivesChunk = previousChunk;
previousChunk = currentChunk;
currentChunk = nextChunk;
nextChunk = refToprivesChunk;
float xPosition = nextChunk.transform.position.x+3 * nextChunk.WidthGroundPrefab * chunk.CHUNK_SIZE;
nextChunk.RepositionChunk (new Vector3(xPosition,0,0));
}
}
を探しているパスのyの値であるあなたが生成する方法についていくつかのより多くの情報を提供し、あなたのパス – TheDjentleman
を表すことができ、あなたの生成されたパスは、コライダーを持っていますか?見た目の写真を投稿してもいいですか? – Programmer
はいパス上にポリゴンコライダーを追加しました(上記の図を参照) – Destro