forked from RonenNess/UnityUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added some randomizers and updated texture fan
- Loading branch information
Showing
9 changed files
with
115 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# RandomDoodadsGenerator | ||
|
||
Create random objects spread across the prefab when it spawns. |
60 changes: 60 additions & 0 deletions
60
Randomizers/RandomDoodadsGenerator/RandomDoodadsGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Add random doodads on tile. | ||
* | ||
* Author: Ronen Ness. | ||
* Since: 2018. | ||
*/ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Ness.Graphics { | ||
|
||
/// <summary> | ||
/// Add random doodads on tile. | ||
/// </summary> | ||
public class RandomDoodadsGenerator : MonoBehaviour { | ||
|
||
// size of a single tile square | ||
public static readonly float TileSize = 2; | ||
|
||
/// <summary> | ||
/// Doodad type and chance to appear. | ||
/// </summary> | ||
[System.Serializable] | ||
public struct DoodadType | ||
{ | ||
// doodad prefab | ||
public GameObject Prefab; | ||
|
||
// occurance chance in percent | ||
public float Chance; | ||
} | ||
|
||
// different types and their chances | ||
public DoodadType[] Types; | ||
|
||
// Use this for initialization | ||
void Start () { | ||
|
||
// create random and seed based on position | ||
System.Random rand = new System.Random((int)(transform.position.x * 12.3f * transform.position.z / 1.234f)); | ||
|
||
// spawn doodads | ||
for (int i = 0; i < Types.Length; ++i) { | ||
if ((float)rand.NextDouble() < Types[i].Chance) { | ||
GameObject newObj = Object.Instantiate (Types [i].Prefab); | ||
newObj.transform.parent = transform; | ||
newObj.transform.position = new Vector3( | ||
transform.position.x + -TileSize + (float)rand.NextDouble () * TileSize, | ||
0, | ||
transform.position.z + -TileSize + (float)rand.NextDouble () * TileSize); | ||
} | ||
} | ||
|
||
// destroy self | ||
Destroy(this); | ||
|
||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# RandomScaler | ||
|
||
Scale the object randomly when start, but use a semi-randomness based on position (so it will remain consistent every time level is loaded). | ||
This script is useful to generate randomness in unimportant level objects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Randomly scales an object, based on position. | ||
* | ||
* Author: Ronen Ness. | ||
* Since: 2018. | ||
*/ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace NesScripts.Graphics | ||
{ | ||
/// <summary> | ||
/// Create random scaling based on object's position. | ||
/// </summary> | ||
public class RandomScaler : MonoBehaviour { | ||
|
||
// min scale | ||
public float MinScale = 0.8f; | ||
|
||
// max scale | ||
public float MaxScale = 1.2f; | ||
|
||
// Use this for initialization | ||
void Start () { | ||
|
||
System.Random rand = new System.Random((int)(transform.position.x * 1234.25 + transform.position.z * 97.5 + transform.position.y)); | ||
float factor = MinScale + ((float)rand.NextDouble() * (MaxScale - MinScale)); | ||
transform.localScale = transform.localScale * factor; | ||
Destroy (this); | ||
} | ||
} | ||
} |