//Create Particle Link public Particle2DLink CreateLink(GameObject object1, GameObject object2, float maxLength) { ParticleRod particleRod = object1.AddComponent <ParticleRod>(); particleRod.Initialize(object1, object2, maxLength); return(object1.GetComponent <ParticleRod>()); }
// Start is called before the first frame update void Start() { GameObject obj1 = GameObject.Find("Rod1"); GameObject obj2 = GameObject.Find("Rod2"); GameObject particleLinkObj = new GameObject("Link" + obj1.name + " " + obj2.name); ParticleRod newParticleRod = particleLinkObj.AddComponent <ParticleRod>(); newParticleRod.Initialize(obj1, obj2, 2); mParticleLinks.Add(newParticleRod); }
// Start is called before the first frame update void Start() { GameObject particleLinkObject = new GameObject("LINK " + GameObject.Find("RodAnchor").name + " " + GameObject.Find("RodPlatform").name); ParticleRod newParticleRod = particleLinkObject.AddComponent <ParticleRod>(); newParticleRod.Initialize(GameObject.Find("RodPlatform"), GameObject.Find("RodAnchor"), 10); ContactResolver.Instance.mParticleLinks.Add(newParticleRod); //Swing Platform GameObject particleLinkObject2 = new GameObject("LINK " + GameObject.Find("SwingAnchor").name + " " + GameObject.Find("SwingPlatform").name); ParticleRod particleRod = particleLinkObject.AddComponent <ParticleRod>(); particleRod.Initialize(GameObject.Find("SwingPlatform"), GameObject.Find("SwingAnchor"), 10); ContactResolver.Instance.mParticleLinks.Add(particleRod); }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.Alpha1)) { transform.Rotate(Vector3.forward * 1.0f); } if (Input.GetKey(KeyCode.Alpha2)) { transform.Rotate(Vector3.back * 1.0f); } if (Input.GetKeyDown(KeyCode.W)) { mCurrentProjectile += 1; if (mCurrentProjectile == ProjectileType.NumberOfTypes) { mCurrentProjectile = 0; } } if (Input.GetKeyDown(KeyCode.Return)) { if (mCurrentProjectile == 0) { //rod weapon GameObject Projectile1 = Instantiate(bulletPrefab); Projectile1.transform.position = transform.position; Projectile1.transform.rotation = transform.rotation; Projectile1.tag = "Projectile"; Particle2D Projectile1Data = Projectile1.AddComponent <Particle2D>(); Projectile1Data.Mass = rodEndMass1; Projectile1Data.Velocity = transform.up * rodEndVelocity1; Projectile1Data.Acceleration = rodEndAcceleration1; Projectile1Data.DampingConstant = rodEndDampingConstant1; Projectile1Data.shouldIgnoreForces = rodEndshouldIgnoreForces1; ParticleManager.Instance.mParticles.Add(Projectile1Data); GameObject Projectile2 = Instantiate(bulletPrefab); Projectile2.transform.position = transform.position + new Vector3(0, 1, 0);; Projectile2.transform.rotation = transform.rotation; Projectile2.tag = "Projectile"; Particle2D Projectile2Data = Projectile2.AddComponent <Particle2D>(); Projectile2Data.Mass = rodEndMass2; Projectile2Data.Velocity = transform.up * rodEndVelocity2; Projectile2Data.Acceleration = rodEndAcceleration2; Projectile2Data.DampingConstant = rodEndDampingConstant2; Projectile2Data.shouldIgnoreForces = rodEndshouldIgnoreForces2; ParticleManager.Instance.mParticles.Add(Projectile2Data); GameObject particleLinkObject = new GameObject("LINK " + Projectile1.name + " " + Projectile2.name); ParticleRod newParticleRod = particleLinkObject.AddComponent <ParticleRod>(); newParticleRod.Initialize(Projectile1, Projectile2, 2); ContactResolver.Instance.mParticleLinks.Add(newParticleRod); } else { //spring weapon GameObject Projectile1 = Instantiate(bulletPrefab); Projectile1.transform.position = transform.position; Projectile1.transform.rotation = transform.rotation; Projectile1.tag = "Projectile"; Particle2D Projectile1Data = Projectile1.AddComponent <Particle2D>(); Projectile1Data.Mass = springEndMass1; Projectile1Data.Velocity = transform.up * springEndVelocity1; Projectile1Data.Acceleration = springEndAcceleration1; Projectile1Data.DampingConstant = springEndDampingConstant1; Projectile1Data.shouldIgnoreForces = springEndshouldIgnoreForces1; ParticleManager.Instance.mParticles.Add(Projectile1Data); GameObject Projectile2 = Instantiate(bulletPrefab); Projectile2.transform.position = transform.position + new Vector3(0, 1, 0); Projectile2.transform.rotation = transform.rotation; Projectile2.tag = "Projectile"; Particle2D Projectile2Data = Projectile2.AddComponent <Particle2D>(); Projectile2Data.Mass = springEndMass2; Projectile2Data.Velocity = transform.up * springEndVelocity2; Projectile2Data.Acceleration = springEndAcceleration2; Projectile2Data.DampingConstant = springEndDampingConstant2; Projectile2Data.shouldIgnoreForces = springEndshouldIgnoreForces2; ParticleManager.Instance.mParticles.Add(Projectile2Data); ForceManager.Instance.CreateSpringForceGenerator(Projectile1, Projectile2, springConstant, restLength); } } }