Hello,
I am unable to set the localPosition of coins Instantiated on of a Supersline.
On Y-Axis View
=================
0 0 0 0 0 0 ---X-AXIS-->
=================
When I set the position of each coin to (1f, 0f, 0f), I get:
=================
0 0 0 0 0 0 ---X-AXIS-->
=================
Notice the all coins are shifted to the left. (Shifted using the World positioning)
The desired result would be something like:
=================
---X-AXIS-->
0 0 0 0 0 0
=================
Where the coins are shifted to their Left/Right.
The script below, I attach it to my “Superspline”.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
//This class computes a point on a spline that is as close as possible to a given gameobject
public class CoinPlacement : MonoBehaviour
{
public Spline spline;
public GameObject prefabCoin;
public GameObject prefabCoinBig;
public int coinCount = 100;
public int coinsInEachGroup = 5;
void Start( )
{
int coinGroupCount = (coinCount / coinsInEachGroup)+coinsInEachGroup;
GameObject[] prefabs = new GameObject[2] {prefabCoin, prefabCoinBig};
System.Random rnd = new System.Random();
//Create an array with intervals we wan.
//EG: starting points every 5 "steps"
int[] coinStartPoints = new int[coinGroupCount];
for (int i = 0; i < coinGroupCount; i++) {
coinStartPoints _= (i+(i+coinsInEachGroup))*coinsInEachGroup;_
}
for (int i = 0; i < coinCount; i++) {
//put coins in succession. EG in 12345 in a straight line
for(int x=0; x<coinStartPoints.Length; x++) {
if(i == coinStartPoints[x]) {
for(int k=0; k<coinsInEachGroup; k++) {
cloneCoin(i+k, prefabs);
}
i = i + coinsInEachGroup;
}
}
}
}
private void cloneCoin(int i, GameObject[] prefabs) {
GameObject clone;
clone = Instantiate(
prefabs[0],
Vector3.Lerp (
spline.GetPositionOnSpline(0),
spline.GetPositionOnSpline(i / (float)coinCount),
1
) + new Vector3(0f,coinYOffset,0f),
spline.GetOrientationOnSpline(i)
) as GameObject;
Debug.Log(clone.transform.position);
clone.transform.parent = transform;
clone.transform.localPosition = new Vector3(1f, 0f, 0f);
Debug.Log("after: "+clone.transform.position);
}
void Update() {
}
}
Thanks!
W