FANDOM


(Created page with "This script demonstrates how AC can make use the free [https://assetstore.unity.com/packages/tools/input-management/simple-touch-controller-74107 Simple Touch Controller] asse...")
 
(Added note regarding use with touch-screen and direct movement)
 
Line 1: Line 1:
 
This script demonstrates how AC can make use the free [https://assetstore.unity.com/packages/tools/input-management/simple-touch-controller-74107 Simple Touch Controller] asset. It allows for joysticks to override the Horizontal and Vertical axes, as well as free-aiming.
 
This script demonstrates how AC can make use the free [https://assetstore.unity.com/packages/tools/input-management/simple-touch-controller-74107 Simple Touch Controller] asset. It allows for joysticks to override the Horizontal and Vertical axes, as well as free-aiming.
  +
  +
'''Note:''' If you are using '''Direct '''movement and '''Touch Screen i'''nput, you must set the Settings Manager's '''Direct movement''' field to '''Custom Input'''.
   
 
Attach the script to any active object in the hierarchy, and configure the fields. Note that the "CustomGetFreeAim" method is only useful in first-person, and can be removed if you're not using it.
 
Attach the script to any active object in the hierarchy, and configure the fields. Note that the "CustomGetFreeAim" method is only useful in first-person, and can be removed if you're not using it.

Latest revision as of 02:56, May 2, 2018

This script demonstrates how AC can make use the free Simple Touch Controller asset. It allows for joysticks to override the Horizontal and Vertical axes, as well as free-aiming.

Note: If you are using Direct movement and Touch Screen input, you must set the Settings Manager's Direct movement field to Custom Input.

Attach the script to any active object in the hierarchy, and configure the fields. Note that the "CustomGetFreeAim" method is only useful in first-person, and can be removed if you're not using it.

ACInputSTC.cs:

using UnityEngine;

public class ACInputSTC: MonoBehaviour
{

public SimpleTouchController moveController;
public SimpleTouchController aimController;


void Start ()
{
AC.KickStarter.playerInput.InputGetAxisDelegate = CustomGetAxis;
AC.KickStarter.playerInput.InputGetFreeAimDelegate = CustomGetFreeAim;
}


private float CustomGetAxis (string axisName)
{
if (axisName == "Horizontal")
{
return moveController.GetTouchPosition.x;
}
if (axisName == "Vertical")
{
return moveController.GetTouchPosition.y;
}

try
{
return Input.GetAxis (axisName);
}
catch
{
return 0f;
}
}


private Vector2 CustomGetFreeAim (bool cursorIsLocked)
{
return aimController.GetTouchPosition;
}

}
Community content is available under CC-BY-SA unless otherwise noted.