I am new to unity and I am trying to instantiate an item to thereafter change two variables inside it. I don’t get any compiler errors, but none of the varables changed.
heres the script i want to change the value X and Y in:
using UnityEngine;
using System.Collections;
public class Point : MonoBehaviour {
public GameObject grass;
public GameObject sand;
float WGenMain;
public float minidelay = 0.01f;
public float Type = 0;
public float X;
public float Y;
// Use this for initialization
void Start ()
{
StartCoroutine (Wait ());
}
IEnumerator Wait()
{
yield return new WaitForSeconds(1);
WGenMain = Random.Range(0, 100);
//This will be refined significantly
if (WGenMain > 50)
{
Type = 1;
}
if (WGenMain < 50)
{
Type = 2;
}
if (Type == 1)
{
Instantiate (grass, transform.position, Quaternion.identity);
}
if (Type == 2)
{
Instantiate (sand, transform.position, Quaternion.identity);
}
}
// Update is called once per frame
void Update () {
}
}
here’s the script which tries to change those two variables:
using UnityEngine;
using System.Collections;
public class Xgen : MonoBehaviour {
public GameObject Grass;
public GameObject point;
float NameNumber = 1;
// Use this for initialization
void Start ()
{
if (this.name == "X")
{
}
else
{
float name = float.Parse (this.name);
for (int i = 0; i < GameObject.Find ("Source").GetComponent<Sourcegenerator> ().Cube_radius * 2; i++) {
var Object = Instantiate (point, new Vector3 (transform.position.x, i * 12 - GameObject.Find ("Source").GetComponent<Sourcegenerator> ().Cube_radius * 12, transform.position.z), Quaternion.identity);
Object.name = (this.name + "," + NameNumber);
float X = GameObject.Find (this.name + "," + NameNumber).GetComponent<Point> ().X;
float Y = GameObject.Find (this.name + "," + NameNumber).GetComponent<Point> ().Y;
X = 69f;
Y = NameNumber;
NameNumber++;
}
}
}
void LateUpdate()
{
Destroy(GameObject.Find("" + this.name));
}
// Update is called once per frame
void Update () {
}
}
I looked at all the other questiopns asked and none of them helped me. Thanks in advance.