public GameObject GetPaintballFromPool() { // Check for objects in the pool if (paintballPool.Count > 0) { // Get the last object in the pool GameObject paintball = paintballPool.Pop(); paintball.GetComponent <PaintProjectileBehavior>().startPoint = Camera.main.transform.position + Camera.main.transform.forward * 3; paintball.gameObject.SetActive(true); return(paintball); } // creates a new paintball. return(Instantiate(PaintProjectileManager.GetInstance().paintBombPrefab, Camera.main.transform.position + Camera.main.transform.forward * 3, Camera.main.transform.rotation)); }
void OnTriggerEnter(Collider other) { // Adds paintballs to the pool PaintballPool.instance.AddPaintballToPool(gameObject); // creates particle effects. ParticleSystem cloudParticle = Instantiate(PaintProjectileManager.GetInstance().cloudParticlePrefab); ParticleSystem burstParticle = Instantiate(PaintProjectileManager.GetInstance().burstParticlePrefab); MyShaderBehavior script = null; cloudParticle.transform.position = transform.position; burstParticle.transform.position = transform.position; var cloudSettings = cloudParticle.main; var burstSettings = burstParticle.main; cloudSettings.startColor = paintColor; burstSettings.startColor = paintColor; cloudParticle.Play(); burstParticle.Play(); PaintProjectileManager manager = PaintProjectileManager.GetInstance(); for (int i = 0; i < 14; ++i) { if (Physics.Raycast(transform.position, manager.GetSphereRay(i), out RaycastHit hit, paintDiameter)) { if (hit.collider is MeshCollider) { script = hit.collider.gameObject.GetComponent <MyShaderBehavior>(); if (null != script) { script.PaintOnColored(hit.textureCoord2, manager.GetRandomProjectileSplash(), paintColor); script.PaintOnColored(hit.textureCoord2, manager.GetRandomProjectileSplash(), paintColor); } } } } if (script != null) { float value = TextureColorFillCalculator.CalculateFill(GetObjectTexture().GetPixels(), paintColor, 0) * 100; menuController.SetSliderValue(value); } }
void Update() { if (cameraController.isFps && gameManager.isGame) { if (passingTime < shotTime) { passingTime += Time.deltaTime; } else { if (Input.GetMouseButton(0)) { passingTime = 0; Vector3 touchPoint = CalculateShootRay(); if (touchPoint != Vector3.zero) { GameObject paintball = PaintballPool.instance.GetPaintballFromPool(); paintball.GetComponent <PaintProjectileBehavior>().target = CalculateShootRay(); //sends its destination paintball.GetComponent <PaintProjectileBehavior>().paintColor = PaintProjectileManager.GetInstance().paintBombColor; } if (menuController.CheckSliderValue()) { StartCoroutine(FindObjectOfType <GameManager>().WinGame()); } } } } }