The concept of using touch events to modify things in the game can also be applied to other methods of touch interaction such as using finger pinches to zoom in and out. To see how to do this, let's make it so we can change the player's scale using two fingers to pinch or stretch out the view:
- Open up the PlayerBehaviour script and add the following properties:
[Header("Scaling Properties")]
[Tooltip("The minimum size (in Unity units) that the player should be")]
public float minScale = 0.5f;
[Tooltip("The maximum size (in Unity units) that the player should be")]
public float maxScale = 3.0f;
/// <summary>
/// The current scale of the player
/// </summary>
private float currentScale = 1;
- Next, add the following function:
/// <summary>
/// Will change the player's scale via pinching and stretching two
/// touch events
/// </summary>
private void ScalePlayer()
{
// We must have two touches...