private void Start() { if (!shouldIgnoreBouyancy) { mBouyancyForce = new BouyancyForceGenerator(true, gameObject, -6, 50, 0); GameManager.Instance.mForceManager.addForceGenerator(mBouyancyForce); } }
//Create Bouyancy Force Generator public ForceGenerator2D CreateBouyancyForceGenerator(GameObject gameObject1, float bouyancy, float volume, float density, float depth) { //GameObject forceGenerator = new GameObject("BouyancyForceGenerator"); BouyancyForceGenerator newGenerator = gameObject.AddComponent <BouyancyForceGenerator>(); newGenerator.Initialize(gameObject1, bouyancy, volume, density, depth); AddForceGenerator(newGenerator); return(gameObject.GetComponent <ForceGenerator2D>()); }
public void CreateProjectile(GameObject projectile, Transform spawnPoint, Transform playerPos) { float speed = 0.0f; Vector2 angle = new Vector2(spawnPoint.position.x - playerPos.position.x, spawnPoint.position.y - playerPos.position.y); Vector2 gravity; PhysicsObject2D proj; GameObject part; switch (mCurrentWeaponType) { case WeaponType.SPRING: { speed = 20.0f; float speed2 = 15.0f; gravity = new Vector2(0.0f, -6.0f); float mass1, mass2; mass1 = 1.0f; mass2 = 2.0f; part = Instantiate(projectile, spawnPoint.position, spawnPoint.rotation); mParticleManager.AddParticle(part.GetComponent <Particle2D>()); proj = part.GetComponent <PhysicsObject2D>(); proj.SetVel(angle * speed); proj.SetAcc(gravity); proj.SetInverseMass(mass1); proj.SetDamping(0.99f); mPhysicsObjects.Add(proj); PhysicsObject2D proj2; part = Instantiate(projectile, spawnPoint.position - new Vector3(1.0f, 0.0f, 0.0f), spawnPoint.rotation); proj2 = part.GetComponent <PhysicsObject2D>(); mParticleManager.AddParticle(part.GetComponent <Particle2D>()); proj2.SetVel(angle * speed2); proj2.SetAcc(gravity); proj2.SetInverseMass(mass2); proj2.SetDamping(0.99f); mPhysicsObjects.Add(proj2); proj2.gameObject.AddComponent <DestroyOnExit>(); SpringForceGenerator springForceGenerator = new SpringForceGenerator(proj, proj2, 1.0f, 50.0f, true); proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(springForceGenerator); mForceManager.AddForceGenerator(springForceGenerator); BouyancyForceGenerator bGenerator = new BouyancyForceGenerator(true, proj, -6, 100, 0); mForceManager.AddForceGenerator(bGenerator); proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(bGenerator); bGenerator = new BouyancyForceGenerator(true, proj2, -6, 100, 0); mForceManager.AddForceGenerator(bGenerator); proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(bGenerator); } break; case WeaponType.ROD: { speed = 30.0f; gravity = new Vector2(0.0f, -6.0f); proj = Instantiate(projectile, spawnPoint.position, spawnPoint.rotation).GetComponent <PhysicsObject2D>(); proj.SetVel(angle * speed); proj.SetAcc(gravity); proj.SetInverseMass(1.0f); proj.SetDamping(0.99f); mPhysicsObjects.Add(proj); PhysicsObject2D proj2; proj2 = Instantiate(projectile, spawnPoint.position + new Vector3(2.5f, 0.0f), spawnPoint.rotation).GetComponent <PhysicsObject2D>(); proj2.SetVel(angle * speed); proj2.SetAcc(gravity); proj2.SetInverseMass(1.0f); proj2.SetDamping(0.99f); mPhysicsObjects.Add(proj2); proj2.gameObject.AddComponent <DestroyOnExit>(); Particle2DLink link = new ParticleRod(proj, proj2, 5.0f); AddParticleLink(link); BouyancyForceGenerator bGenerator = new BouyancyForceGenerator(true, proj, -6, 100, 0); mForceManager.AddForceGenerator(bGenerator); proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(bGenerator); bGenerator = new BouyancyForceGenerator(true, proj2, -6, 100, 0); mForceManager.AddForceGenerator(bGenerator); proj2.gameObject.GetComponent <DestroyOnExit>().mForceGenerators.Add(bGenerator); } break; } }