AdjustableSpeedTeleport.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. //***********************************************************
  2. // Filename: AdjustableSpeedTeleport.cs
  3. // Author: Moritz Kolvenbach, Marco Fendrich
  4. // Last changes: Wednesday, 8th of August 2018
  5. // Content: Class that adds an adjustable speed setting via y axis of touchpad to ParabolicTeleport
  6. //***********************************************************
  7. using UnityEngine;
  8. /// <summary>
  9. /// Child class of ParabolicTeleport adding an adjustable speed setting via y axis of touchpad
  10. /// </summary>
  11. public class AdjustableSpeedTeleport : ParabolicTeleport, ITouchpadAxis {
  12. // container for public velocity adjusted in editor which will be overwritten for calculation
  13. private float baseVelocity;
  14. void Awake()
  15. {
  16. // save base velocity as it will be overwritten with adjusted touchpad velocity
  17. baseVelocity = initialVelocity.z;
  18. }
  19. /// <summary>
  20. /// adjust velocity according to position on touchpad so that:
  21. /// y=-1 => 0% of maximum velocity
  22. /// y=+1 => 100% of maximum velocity
  23. /// </summary>
  24. /// <param name="axis">touchpad axis</param>
  25. public void OnButtonPressed(Vector2 axis)
  26. {
  27. initialVelocity.z = (axis.y + 1.0F) * 0.5F * baseVelocity;
  28. }
  29. }