1
Fork 0
mirror of https://github.com/Steffo99/gravity-fusion.git synced 2024-11-22 00:14:18 +00:00

Update some things

This commit is contained in:
Steffo 2019-10-05 23:50:43 +02:00
parent 8e65f4f948
commit ff5bf700fb
13 changed files with 114 additions and 5 deletions

View file

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BigBang : MonoBehaviour
{
public GameObject blackHolePrefab;
public GameObject particlePrefab;
public int particlesToSpawn;
void Start()
{
}
void Update()
{
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 39e0b663ea04fd648950255e97005aa4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -12,7 +12,7 @@ public class BlackHole : MonoBehaviour
}
set {
rigidbody.mass = value;
Scale = Mass / Mathf.Pow(Mathf.PI, 2);
Scale = Mathf.Sqrt(Mass / Mathf.PI);
}
}

24
Assets/Components/Emit.cs Normal file
View file

@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Particle))]
public class Emitter : MonoBehaviour
{
public GameObject particlePrefab;
protected Particle particle;
protected void Awake() {
particle = GetComponent<Particle>();
}
protected void Start() {
InvokeRepeating("Emit", 1f, 1f);
}
protected void Emit() {
for(int i = 0; i < particle.Tier - 1; i++) {
Instantiate(particlePrefab, transform.position, Quaternion.identity);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4ae389aca0e2e82408a1ddd869680dc0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -59,7 +59,7 @@ public class Gravitation : MonoBehaviour
foreach(Gravitation other in simulatedObjects) {
if(other.positionInList <= this.positionInList) continue;
float distance = Vector3.Distance(this.transform.position, other.transform.position);
float force = GravitationConstant * this.Mass * other.Mass / Mathf.Pow(distance, 2);
float force = GravitationConstant * this.Mass * other.Mass / Mathf.Clamp(Mathf.Pow(distance, 2), 0.1f, float.PositiveInfinity);
Vector3 direction = (other.transform.position - this.transform.position).normalized;
if(!this.isStatic) rigidbody.AddForce(direction * force);
if(!other.isStatic) other.rigidbody.AddForce(-direction * force);

View file

@ -51,7 +51,11 @@ public class Merger : MonoBehaviour
protected void DoMerge() {
particle.Tier += 1;
foreach(Merger merged in mergeCandidates.ToArray()) {
if(merged == null) continue;
Destroy(merged.particle.gameObject);
}
mergeCandidates.Clear();
particle.mergeCollider.enabled = false;
particle.mergeCollider.enabled = true;
}
}

View file

@ -6,6 +6,7 @@ using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
[RequireComponent(typeof(Collider2D))]
[RequireComponent(typeof(Gravitation))]
[RequireComponent(typeof(Emitter))]
public class Particle : MonoBehaviour {
protected int _tier = 0;
@ -15,6 +16,7 @@ public class Particle : MonoBehaviour {
public Merger merger;
public Collider2D particleCollider;
public Collider2D mergeCollider;
public Emitter emitter;
public int Tier {
get {
@ -48,5 +50,6 @@ public class Particle : MonoBehaviour {
merger = GetComponentInChildren<Merger>();
particleCollider = GetComponent<Collider2D>();
mergeCollider = merger.GetComponent<Collider2D>();
emitter = GetComponent<Emitter>();
}
}

View file

@ -14,7 +14,7 @@ public class SpawnOnMouseClick : MonoBehaviour
void Update()
{
if(Input.GetMouseButtonDown(mouseButton)) {
if(Input.GetMouseButton(mouseButton)) {
Vector3 mousePosition = GetWorldMousePosition();
GameObject instance = Instantiate(prefabToSpawn, new Vector3(mousePosition.x, mousePosition.y, 0f), Quaternion.identity);
}

View file

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TextFromBlackHoleMass : MonoBehaviour
{
protected Text text;
public BlackHole blackHole;
protected void Awake() {
text = GetComponent<Text>();
}
protected void Update()
{
text.text = blackHole.Mass.ToString("0");
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1902801cf75c7ea4f82979802e80aaef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -202,7 +202,7 @@ CircleCollider2D:
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
serializedVersion: 2
m_Radius: 0.55
m_Radius: 0.75
--- !u!114 &7106168952007636313
MonoBehaviour:
m_ObjectHideFlags: 0

View file

@ -3,7 +3,7 @@
--- !u!30 &1
GraphicsSettings:
m_ObjectHideFlags: 0
serializedVersion: 12
serializedVersion: 13
m_Deferred:
m_Mode: 1
m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0}
@ -31,6 +31,9 @@ GraphicsSettings:
m_AlwaysIncludedShaders:
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
@ -55,3 +58,5 @@ GraphicsSettings:
m_AlbedoSwatchInfos: []
m_LightsUseLinearIntensity: 0
m_LightsUseColorTemperature: 0
m_LogWhenShaderIsCompiled: 0
m_AllowEnlightenSupportForUpgradedProject: 1