Hi, I just started learning game development with unity and I just ran into a problem. I created a spawner and the clones don’t appear in game view. It is really strange because the clones appear in the hierarchy and in the scene view. Their Box Colliders work so the character you play gets pushed by the clones, even if they are invisible.
Here is my code for the spawner:
public class MonsterSpawner : MonoBehaviour
{
[SerializeField]
private GameObject[ ] monsterReference;
Hm, that is odd… Select them in the hierarchy and press F in the scene to focus. That will show them. Pull back and see where the camera is, make sure it’s pointed where you think, etc… try replace them with a Cube… check their scales, etc.
I replaced them with cubes, and I still don’t see them in the game view. Also, the camera is following the player. I can see the cubes in game view when they are the original prefabs. Thank you for helping me.
Then you’ve found a smoking gun. We know that cubes work fine and camera’s work fine. Don’t even consider ANYTHING else until you have a cube rendering.
I was just following the same tutorial actually and came here, i miss read banga comment and thought he was saying (set z scale to 1) when i checked my code i had my scale as following
spawnedMonster.transform.localScale = new Vector3(multiplier, 0, 0);
Don’t worry about multiplier, it’s just a variable for either -1 or 1, something i made to make my code simpler, anyways if you accidently made the scale for those two at 0 then your character is 0 pixel tall aka invisible, make sure they are at 1, did this fix the issue for you? if not here is my code, you can compare it to yours
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonsterSpawner : MonoBehaviour
{
[SerializeField] GameObject[] monsterRef;
[SerializeField] Transform[] positions;
GameObject spawnedMonster;
int randomI;
int randomPos;
int multiplier;
void Start()
{
StartCoroutine(SpawnMonsters());
}
IEnumerator SpawnMonsters()
{
while (true)
{
yield return new WaitForSeconds(Random.Range(1, 3));
randomI = Random.Range(0, monsterRef.Length);
randomPos = Random.Range(0, 2);
spawnedMonster = Instantiate(monsterRef[randomI]);
spawnedMonster.transform.position = positions[randomPos].position;
if (randomPos == 0) { multiplier = 1; } else { multiplier = -1; }
spawnedMonster.GetComponent<Monster>().speed = Random.Range(3, 10) * multiplier;
spawnedMonster.transform.localScale = new Vector3(multiplier, 1, 1);
}
}
}
Bonjours, moi j’ai un problème similaire pour un puissance 4: les pions spawn bien dans la scène et la hiérarchiemais pas dans le “Game”. Les pions spawn à un “Transform”.
Voici mon code :
```[ICODE]```[/ICODE]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ActionButton : MonoBehaviour
{
public Transform lachePoint1;
bool isYellow = true;
public GameObject yellowPiece;
public GameObject redPiece;
void Start()
{
}
void Update()
{
}
public void OnClick()
{
if(isYellow == true)
{
Instantiate(yellowPiece, lachePoint1.position, lachePoint1.rotation);
isYellow = false;
}
else
{
Instantiate(redPiece, lachePoint1.position, lachePoint1.rotation);
isYellow = true;
}
}
}
Ive had the same problem as well, and the solution to my case was setting the Z-axis coordinate of the Spawner object to 0.
I believe the reason why this happens is because the references rightPos and leftPos doesn’t refer to the z coordinates of the Right and Left game objects, which are placed in the Spawner object. Thus the z coordinates of the Spawned monsters are automatically set to the z coordinate of the Spawner object which is the parent of the Right and Left.