void CreateConnection(GameObject other) { GameObject c = Instantiate(connectionPrefab); RopeConnector rope = c.GetComponent <RopeConnector>(); rope.From = other; rope.To = this.gameObject; rope.Reset(); print(c); connection = c; }
void OnTriggerEnter(Collider other) { if (other.tag == "soul") { audio.Play(); insideSoul = true; if (connection != null) { Soul s = other.gameObject.GetComponent <Soul>(); RopeConnector r = connection.GetComponent <RopeConnector>(); bool canMake = true; for (var i = 0; i < s.connections.Count; i++) { RopeConnector oRC = s.connections[i].GetComponent <RopeConnector>(); if (oRC.From == r.From && oRC.To == other.gameObject) { canMake = false; } if (oRC.From == r.To && oRC.To == other.gameObject) { canMake = false; } if (oRC.From == other.gameObject && oRC.To == r.From) { canMake = false; } if (oRC.From == other.gameObject && oRC.To == r.To) { canMake = false; } } if (r.From != other.gameObject && canMake == true) { r.To = other.gameObject; s.connections.Add(connection); r.From.GetComponent <Soul>().connections.Add(connection); connection = null; } } } }
// Use this for initialization void Start() { rope = GetComponent <RopeConnector>(); particleMat = new Material(particleMat); _buffer = new ComputeBuffer(numberParticles, vertStructSize * sizeof(float)); vertValues = new float[numberParticles * vertStructSize]; //print( nrGroups); nrGroups = (numberParticles + (nrThreads - 1)) / nrThreads; int index = 0; for (int i = 0; i < numberParticles; i++) { // positions vertValues[index++] = 0; vertValues[index++] = 0; vertValues[index++] = 0; // vel vertValues[index++] = 0; vertValues[index++] = 0; vertValues[index++] = 0; // uv vertValues[index++] = i; vertValues[index++] = (float)i / (float)numberParticles; // life vertValues[index++] = -1 + Random.Range(0, .99f); // debug vertValues[index++] = 1; vertValues[index++] = 0; vertValues[index++] = 0; } _buffer.SetData(vertValues); }
// Update is called once per frame void Update() { for (int i = 0; i < numberStars; i++) { Rigidbody star1 = bodies[i]; Vector3 dif = star1.position - center; star1.AddForce(-dif * 4); for (int j = 0; j < numberStars; j++) { Rigidbody star2 = bodies[j]; dif = star1.position - star2.position; star1.AddForce(.8f * -dif.normalized * (dif.magnitude - size)); star2.AddForce(.8f * dif.normalized * (dif.magnitude - size)); } } float m = 1000; float id = 1000; for (int i = 0; i < numberRopes; i++) { RopeConnector r = ropes[i].GetComponent <RopeConnector>(); if (r.finalFloats[0] < m) { m = r.finalFloats[0]; id = r.finalFloats[1]; } } if (m < 1000) { player.amount = .0003f / m; player.pitch = .0003f / m; player.offset = .01f / m; } }