Answer the question
In order to leave comments, you need to log in
How to change the position of a child object on creation (curatin)?
Hello.
When creating a child game object, let's say Cube , I want to change its position relative to the parent, according to the parent's vector, but so far I'm at an impasse.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Strike : MonoBehaviour
{
public GameObject Cube;
public void SetParent(GameObject Sphere)
{
Cube.transform.parent = Sphere.transform;
}
void Update()
{
if (Input.GetMouseButtonDown(0))
StartCoroutine(instObj());
Cube.transform.position = transform.position;
}
IEnumerator instObj()
{
yield return new WaitForSeconds(0f);
Instantiate(Cube);
}
}
instCube = Instantiate(Cube) as GameObject;
instCube.transform.localPosition = new Vector3(0f, 25f, 0);
instCube.transform.position = transform.position;
Answer the question
In order to leave comments, you need to log in
so let's try to figure it out
instCube.transform.localPosition = new Vector3(0f, 25f, 0);
instCube.transform.position = transform.position;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question