Hi there! So I have a portal that spawns enemies through scripting. I want to make it so that the item’s spawn are at the same transformation as the portal, even when it is moving. The videos I have in the post show what normally happens when the portal is not moving and the second one shows what happens when the portal is moving.
code is needed.
It looks like the spawning object (the object that is running the spawning script) is a separate object from the moving platform. I would make the spawning object a sub-object of the moving platform.
Unless the spawning script is saying to spawn at Vector3(0,0,0). that would have all the object spawning at the same position.
using UnityEngine;
using System.Collections;
public class GreenShell : MonoBehaviour
{
public float delayR = 0.1f;
public float delayL = 0.1f;
public GameObject GreenShellRight;
public GameObject GreenShellLeft;
public float range1;
public float range2;
public float hight1;
public float hight2;
// Use this for initialization
void Start()
{
InvokeRepeating("SpawnRight", delayR, delayR);
InvokeRepeating("SpawnLeft", delayL, delayL);
}
// Update is called once per frame
void SpawnRight()
{
Instantiate(GreenShellRight,new Vector3(Random.Range(range1, range2), Random.Range(hight1, hight2), 0), Quaternion.identity);
}
void SpawnLeft()
{
Instantiate(GreenShellLeft,new Vector3(Random.Range(range1, range2), Random.Range(hight1, hight2), 0), Quaternion.identity);
}
}
yep, you are specifying a Vector3 spawning location.
try this code
using UnityEngine;
using System.Collections;
public class GreenShell : MonoBehaviour
{
public float delayR = 0.1f;
public float delayL = 0.1f;
public GameObject GreenShellRight;
public GameObject GreenShellLeft;
public float range1;
public float range2;
public float hight1;
public float hight2;
public GameObject platform; // set this in the inspector
// Use this for initialization
void Start()
{
InvokeRepeating("SpawnRight", delayR, delayR);
InvokeRepeating("SpawnLeft", delayL, delayL);
}
// Update is called once per frame
void SpawnRight()
{
//Instantiate(GreenShellRight,new Vector3(Random.Range(range1, range2), Random.Range(hight1, hight2), 0), Quaternion.identity);
Instantiate(GreenShellRight,new Vector3(platform.transform.position.x,platform.transform.position.y, 0), Quaternion.identity);
}
void SpawnLeft()
{
//Instantiate(GreenShellLeft,new Vector3(Random.Range(range1, range2), Random.Range(hight1, hight2), 0), Quaternion.identity);
Instantiate(GreenShellLeft,new Vector3(platform.transform.position.x,platform.transform.position.y, 0), Quaternion.identity);
}
}