Global variable gap:
public int gap = 10;
Then:
clone.position = new Vector3(transform.position.x, 0,0);
clone is Transform
I want to use the gap variable to make spaces between each clone:
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
public class ClickOnKeys : MonoBehaviour
{
public GameObject[] prefabs;
public int gap = 10;
private GameObject go;
void Start()
{
prefabs = Resources.LoadAll("Prefabs", typeof(GameObject)).Cast<GameObject>().ToArray();
foreach (GameObject prefab in prefabs)
{
if (prefab.name == "Test")
{
go = prefab;
}
}
}
void Update()
{
if (Input.anyKey)
{
foreach (Transform child in go.transform)
{
if (Input.inputString == child.name)
{
Transform clone = Instantiate(child);
clone.parent = transform;
clone.position = new Vector3(transform.position.x + gap += 50, 0,0);
}
}
}
}
}
I tried to make:
clone.position = new Vector3(transform.position.x + gap += 50, 0,0);
But getting error on the part: transform.position.x + gap
The left-hand side of an assignment must be a variable, property or indexer The
This is what i tried now:
Transform clone = Instantiate(child);
clone.parent = transform;
gap += 50;
clone.position = new Vector3(transform.position.x - gap, 0, 0);
But the result is that the space/gap between the clones is not equal and also it seems the clones that each one is a letter looks rotated like mirror:
Each clone present a letter so it should show the word Hello But the letter e is on the H and the gap/space between the first l and second l not equal and the l is on the o: