Why is this not setting the int value variables correctly for each set of 9 sprites should be set 1,2,3, instead they are being set to 0,1,2,3? - I intend to set them all from 1 to 9 once I get this work right. Inspector didn’t work for “value” variable and now it is so can preset the first one to 1 but still it is setting the wrong values to the instances.
using UnityEngine;
public class GridManager2 : MonoBehaviour
{
// The GameObject to instantiate.
public GameObject G1;
public float variance;
public float xdispl;
public float xspace;
public float ydispl;
public float yspace;
//static Sprite[ ] SA;
//private int SAN;
void Start()
{
SpawnEntities();
}
void SpawnEntities()
{
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
//xdispl -300
//xspace 30
//ydispl 150
//yspace 30
Vector3 position;
position = new Vector3((-1*variance + xdispl + (i * xspace)), (variance + ydispl - (j * yspace)), 0);
GameObject a=Instantiate(G1,position, Quaternion.identity);
a.GetComponent().value = 1;
position = new Vector3(0 + xdispl + (i * xspace), variance + ydispl - (j * yspace), 0);
Instantiate(G1, position, Quaternion.identity);
position = new Vector3(((variance + xdispl + (i * xspace))), (variance + ydispl - (j * yspace)), 0);
a=Instantiate(G1, position, Quaternion.identity);
a.GetComponent().value = 2;
position = new Vector3((-1variance + xdispl + (i * xspace)), (0 + ydispl - (j * yspace)), 0);
a=Instantiate(G1, position, Quaternion.identity);
a.GetComponent().value = 3;
position = new Vector3(0 + xdispl + (i * xspace), 0 + ydispl - (j * yspace), 0);
Instantiate(G1, position, Quaternion.identity);
position = new Vector3((variance + xdispl + (i * xspace)), (0 + ydispl - (j * yspace)), 0);
Instantiate(G1, position, Quaternion.identity);
position = new Vector3((-1variance + xdispl + (i * xspace)), (-1*variance + ydispl - (j * yspace)), 0);
Instantiate(G1, position, Quaternion.identity);
position = new Vector3((0 + xdispl + (i * xspace)), (-1variance + ydispl - (j * yspace)), 0);
Instantiate(G1, position, Quaternion.identity);
position = new Vector3((variance + xdispl + (i * xspace)), (-1variance + ydispl - (j * yspace)), 0);
Instantiate(G1, position, Quaternion.identity);
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tileimage : MonoBehaviour
{
public int value;
public Sprite G1;
public Sprite G2;
public Sprite G3;
public Sprite G4;
public Sprite G5;
public Sprite G6;
public Sprite G7;
public Sprite G8;
public Sprite G9;
// Start is called before the first frame update
void Start()
{
SelectImage();
}
void SelectImage()
{
if (value == 1)
{
this.gameObject.GetComponent().sprite = G1;
}
else if (value == 2)
{
this.gameObject.GetComponent().sprite = G2;
}
else if (value == 3)
{
this.gameObject.GetComponent().sprite = G3;
}
else if (value == 4)
{
this.gameObject.GetComponent().sprite = G4;
}
else if (value == 5)
{
this.gameObject.GetComponent().sprite = G5;
}
else if (value == 6)
{
this.gameObject.GetComponent().sprite = G6;