This question was
closed Nov 07, 2016 at 01:52 PM by
Landern for the following reason:
Duplicate of http://answers.unity3d.com/questions/1268208/spawn-in-specifrc-areas-only.html
spawn in specific areas only
I am trying to make this prefab spawn in certain areas only,
yes I want random spawns in the specific area but only 2 per
every 4 seconds so criteria 1 random location spawns in the specific spawn area 2 only about 2 per every 4 seconds after the others have died
or left scene
when I play this it freezes my scene I read, I have to setup a empty gameobject area and use it
as a spawn point but even when I test this code it freezes and or spawns many
this is a 2d game and c#
using UnityEngine;
using System.Collections;
public class fish2 : MonoBehaviour {
private Vector3 spawnPosition = new Vector3 (-4.62f, 2, 0);
private Vector3 position1 = new Vector3 (2, 2, 0);
public GameObject fishPrefab;
public float Speed;
void Start()
{
// To Spawn:
GameObject fish = Instantiate (fishPrefab, spawnPosition, Quaternion.identity) as GameObject;
}
InvokeRepeating("Launchfish", 2.0f, 6.0f);
// To move:
fish. transform.position = Vector3.MoveTowards(fish.transform.position, position1, Speed * Time.deltaTime);
}
void Launchfish () {
Rigidbody2D instance = Instantiate(fishPrefab);
instance.velocity = Random.insideUnitSphere * 5;
// Starting in 2 seconds.
// a projectile will be launched every 0.3 seconds
//public Rigidbody2D projectile;
//void Start() {
//InvokeRepeating("LaunchProjectile", 2.0f, 6.0f);
//}
/*
void LaunchProjectile () {
Rigidbody2D instance = Instantiate(projectile);
instance.velocity = Random.insideUnitSphere * 5;
}
}
}
}
Comment
Follow this Question
Related Questions
Client Spawning Player Objects 0 Answers
Spawning issues 1 Answer
my objects is spawning on the wall 1 Answer
Random spawn script 1 Answer
Button Script 0 Answers