So there was a few things I needed, yet can’t figure out how to do, even with a google search and any help would be greatly appreciated… (and I’ll try to avoid the assistance questions when it comes to something already made but people are selling like ‘Quest It’)
So yeah, not asking for help on the scripts people sell (that I know of) but a couple of things I am trying to figure out.
I want to make enemies spawn in specific areas, yet still randomize. For example, at the moment I have a monster spawn script that randomly spawns the only three monsters I have (slug, water slug, fire slug). So, where ever I put the spawn points, it chooses one of the three at random to spawn there… which is great and all, however I want let’s say, Fire Slugs to spawn only near volcanos, normal slugs spawn in a forest, and water slugs in a lake or something… how would I do that?..but I’m asking ‘still random’ in regards to… let’s say I have two fire monsters… and I want them to randomly spawn between the two fire monsters, BUT i want them to spawn only near the fire area… (tried to make that as clear as I could, sorry if i didnt)… how would I go about doing that??
The second thing I wanted to ask was I’m making a game for personal use similar to Minecraft, I would love to figure out how to (for example)… attack a patch of dirt to obtain ‘Dirt’… and ect… I’m sure if I can figure that out I will be able to figure out the rest as long as I have the basic formula so to speak.
Lastly, I’m looking for a way to craft items… and just like request #2, I’m sure if I can figure out how to craft one item, I can pretty much discover how to craft all my other times… so any assistance would be GREATLY appreciated…
I prefer using C# however I can’t afford to be picky and would greatly appreciate any help that can be contributed to an amateur programmer.
#1 for the first request as meaning spawn points go here on the unity website and find the 2d or 3d platformer tutorial and look for the spawn scripts or go on www.tornadotwins.com and learn the worm tutorial even do it’s basic it shows you how to make things spawn using a gameobject.
so in simpler terms you would have to make a empty gameobject or cube or anything to use as reference as spawn point and attach the script to make the enemies or things you are trying to make to spawn and to finish the script make it so when something spawns it moves the transform or position so not all of your fire slugs for example would spawn on the same point.
#2 about that second one make a gameobject the item you want to obtain like for example a piece of dirt put a script on it meaning that it should be a game object and use collisions such as if your player shovel hits that dirt at that certain location using maybe a on collision enter script make it so it gives you what you expect such as more dirt for quests and stuff. for on collision enter go to the scripting reference in there it will show you the examples in the different languages since you mention that you wanted to use c#
i’m normally a c++ guy but i decided to just go ahead and learn all the java scripts so i understand how everything works so even do you might want a certain language it will not always be the case so just try to be open to learn a new language since this engine it’s famous for javascripts and it’s seems tp be popular here and then later on you can just translate your scripts or you can try to get a lanuage translator and being honest i don’t remember where did i saw it last time online so try looking first on the wiki i went through so many links there and i found something similar. good luck
oh for the spawning, yeah i have spawn script and i have it working and all, however i have it so all mobs spawn in random spawn points, where as i would like to make specific mobs randomly generate in a specific area
For #1 how about just having different spawn points and scripts.
ie: one for fire slugs, one for water. Then only fire slugs will be ‘attached’ to the fire spawn.
Or if you want one scipt maybe (this is quick…) and completely wrong, just an idea…
if(firespawn)
{
choose from Array (fire monster)
}
else…
if(waterspawn…
I am releasing (free) a script (C#) soon that does the spawning you’re talking about. But, since you have a system you built yourself, you set up a spawn area, spawn points, and the types of monsters you’re spawning in that area. You can easily set up multiple area’s of spawn points instead of just one main one. My script is already done, just not yet released. You can e-mail me if you want a copy beforehand at Ezzerland (at) hotmail (dot) com or PM me here.
few ways to do it, but from what it sounds like you’re looking for, your first responder has the right idea. Use collision to determine that the item your digging up is dirt, and supply dirt to the player. I haven’t the time at the moment (on break at work) to write an example, but it should not be hard to find information about how to use collision detection etc…
Variables that determine how much of materials the player has. It’d be a fairly simple formula to deduct the materials and add the newly crafted one, it’s only a matter of Destroy() and Instantiate() functions to remove the old and create the new assuming they are actual objects you are combining. Animations etc cna be added in later once you get the general functionality.
perhaps you should define a script for your spawnpoint which has an enumerated list of types that can be spawned from it. Your game engine calls SpawnMonster, and the enumerated script could say I can only spawn one of these two types… Furthermore, you could make that same script have enumerations of types. So, fireslug only appears here, and it appears here 999 out of 1000 times. however, 1 out of 1000 times gives you a rare ultraFireSlug, which drops better gear.
So in your code it would look like this:
class Mobs{
var name="";
var commonValue=100;
var monster:Transform;
function Spawn(pos : Vector3){
monster.Instantiate(monster, pos, Quaternion.AngleAxis(Random.value * 360, Vector3.up));
}
}
var rndMobs : Mobs[];
function Start () {
if(rndMobs.length==0)return;
var total=0;
for(mob in rndMobs){
total+=mob.commonValue;
}
var rnd=Mathf.Floor(Random.Range(0,total));
total=0;
for(mob in rndMobs){
if(rnd-total>=mob.commonValue){
mob.Spawn(transform.position);
return;
}else{
total+=mob.commonValue;
}
}
}
Thanks for all the replies. I’m attempting it at the moment, I’m not much of a programmer but I’ll see what I can do. As for Ezzerland I’ll take you up on that script, would make a world of difference for me. Thank you
Script was mailed to you, let me know how it works for you. BigMisterB’s Unityscript version there is actually fairly similar. Since he was kind enough to write that one here, I’ll post mine as well in code-form here. The downloadable of it will include a demo scene and etc (which was included in the e-mail).
This is more or less a simplified version of a more advanced script so some of the comments still refer the previous setup (a multi-spawn system setup). Sorry if any of them are confusing. They will be removed prior to the official release.
using UnityEngine;
using System.Collections;
using System;
[Serializable]
public class simpleEnemyPresets {
public Transform swarmPrefab;
public int chanceToSpawn;
}
public class SimpleSpawnArea : MonoBehaviour {
public bool on = true;
public int spawnCounter = 0; //establish how many monsters will spawn at this area each time it goes through
public int swarmsToSpawn = 0; //what is the maximum amount of swarms that should spawn. 0 = infinite
public int spawnTimer = 10; //default is 10 seconds in between swarms
public int secToStart = 0; //default is to spawn the first swarm instantly
public simpleEnemyPresets[] swarmPrefabs;
public Transform[] spawnPoints; //establish where the monsters can spawn at this area. Set automatically, through spawnPoint
int countOnSpawn = 0;
bool loop;
public void Awake() {
InvokeASwarm();
}
public void InvokeASwarm() {
if (!on)
return;
loop = true;
StartCoroutine(InvokeSwarmSpawn());
}
struct randomSpawn {
public int beginNum;
public int endNum;
}
//This function is what the SetSpawnArea.cs calls to invoke the spawning of a swarm in its area
IEnumerator InvokeSwarmSpawn () {
int randomspawning = 0;
randomSpawn[] rndsp;
rndsp = new randomSpawn[swarmPrefabs.Length];
//establish the total amount of random numbers
for (int i=0; i<swarmPrefabs.Length; i++) {
rndsp[i].beginNum = randomspawning + 1;
randomspawning += swarmPrefabs[i].chanceToSpawn;
rndsp[i].endNum = randomspawning;
}
//go ahead and start the swarms
// Pause for start time
yield return new WaitForSeconds(secToStart);
while (loop) {
// --- Do we continue to loop?
if (swarmsToSpawn > 0) {//yes, cancel after spawn count has been met
countOnSpawn++;
if (countOnSpawn>=swarmsToSpawn) {
//cancel the current swarm
StopSpawning();
}
}
// --- Do the spawning
for (int i=0; i<spawnCounter; i++) {
bool findrand = true;
int rndmSpawn = UnityEngine.Random.Range(1, randomspawning);
int j=0;
while (findrand) {
if (rndmSpawn >= rndsp[j].beginNum rndmSpawn <= rndsp[j].endNum) {
findrand = false;
} else {
j++;
}
}
Transform swarmPref = swarmPrefabs[j].swarmPrefab;
Transform spawnPoint = spawnPoints[UnityEngine.Random.Range(0, spawnPoints.Length)];
Instantiate(swarmPref, spawnPoint.position, spawnPoint.rotation);
}
// Wait before we loop again
yield return new WaitForSeconds(spawnTimer);
}
}
void StopSpawning() {
//if this spawn area was counting its swarms, then make sure we reset it for the next one
countOnSpawn = 0;
loop = false;
}
}