Question by
Totoro205 · Jun 03, 2018 at 02:27 PM ·
transformpositionprefab-instance
Empty object spawn point's global position is wrong at first
Hello, I have an empty object (spawn point) that's a child of another empty object (I'm doing a character selection menu). I would like to instantiate a prefab at the spawn point but at first it arrives in the center and not the appropriate position. When I toggle another button it goes back to global position but i'm calling the came function (which doesn't make sense). Here's my code:
public void Start()
{
if ((OptionsSpawnPoint != null) && (_currentCharacterType == null))
{
SetCurrentCharacterType(_currentIndex);
}
}
public void SetCurrentCharacterType(int index)
{
if (_currentCharacterType != null)
{
Destroy(_currentCharacterType.gameObject);
}
GameObject character = Characters[index];
_currentCharacterType = Instantiate<GameObject>(character,
OptionsSpawnPoint.transform.position, Quaternion.identity);
_currentIndex = index;
}
And here's the toggle button code:
public void ToggleLeft()
{
int index = characterManager._currentIndex;
index--;
if (index < 0)
index = characterManager.Characters.Length - 1;
characterManager.SetCurrentCharacterType(index);
}
alt text
12345.png
(58.8 kB)
123456.png
(47.8 kB)
Comment
Your answer
Follow this Question
Related Questions
Instantiate prefab not in the correct position 1 Answer
How can I make an object transform to given position and rotation 2 Answers
How to tell what method is moving an object? 3 Answers
If two Vector2 are same 1 Answer
How to transform position of one object to the exact position of another object? 0 Answers