/// <summary> /// reflect the projectile and return true if we reflected successfully /// </summary> /// <returns>returns true on reflect</returns> public bool DoReflect(ColorCode.ColorType color, out bool isPerfect) { if (p && p.IsHostile && p.GetColorType() == color) { //super easy way to detect if projectile is in front of us by checking along the only axis we share with projectiles if (p.transform.position.z < _owner.transform.position.z) { isPerfect = false; return(false); } //distance to player float distance = Vector3.SqrMagnitude(_owner.GetCenter() - p.transform.position); //sweet spot if (distance >= _perfectRangeMin && distance < _perfectRangeMax) { p.Reflect(true); _audioPlayer.PlayOneShot(_perfectSound); isPerfect = true; return(true); } else { p.Reflect(false); _audioPlayer.PlayOneShot(_normalSound); isPerfect = false; return(true); } } else { isPerfect = false; return(false); } }
/// <summary> /// Initialize this projectile's speed and color/type /// </summary> /// <param name="speed"></param> /// <param name="cType"></param> public void Initialize(float speed, ColorCode.ColorType cType) { _renderer = GetComponent <Renderer>(); _rb = GetComponent <Rigidbody>(); _rb.velocity = transform.forward * speed; _assignedColor = cType; Color c = ColorCode.ColorCoder.GetColor(cType); _renderer.material.SetColor("_OutlineColor", c); _renderer.material.SetColor("_Color", c); }
/// <summary> /// Cycles the colors on the player /// </summary> private void CycleColor(int direction) { OnColorCycle(direction); _currentTypeIndex += direction; if (_currentTypeIndex < 0) { _currentTypeIndex = 2; } if (_currentTypeIndex > 2) { _currentTypeIndex = 0; } _currentType = (ColorCode.ColorType)_currentTypeIndex; UpdateShader(); }
/// <summary> /// assigns a random color /// </summary> private void AssignColor() { int random = UnityEngine.Random.Range(0, 4); switch (random) { case 0: _currentType = ColorCode.ColorType.orange; break; case 1: _currentType = ColorCode.ColorType.blue; break; case 2: _currentType = ColorCode.ColorType.purple; break; case 3: _currentType = ColorCode.ColorType.black; break; } }