Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity script error

Discussion in 'Scripting' started by halojman, Mar 17, 2016.

  1. halojman

    halojman

    Joined:
    Sep 28, 2015
    Posts:
    27
    Hi, I'm coding and I'm getting this error:

    Assets/Standard Assets/CrossPlatformInput/Scripts/AxisTouchButton.cs(22,56): error CS0117: `UnitySampleAssets.CrossPlatformInput.CrossPlatformInputManager' does not contain a definition for `AxisExists'

    This is my code:

    using System;
    using UnityEngine;
    using UnityEngine.EventSystems;
    using UnitySampleAssets.CrossPlatformInput;

    namespace UnityStandardAssets.CrossPlatformInput
    {
    public class AxisTouchButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
    {
    // designed to work in a pair with another axis touch button
    // (typically with one having -1 and one having 1 axisValues)
    public string axisName = "Horizontal"; // The name of the axis
    public float axisValue = 1; // The axis that the value has
    public float responseSpeed = 3; // The speed at which the axis touch button responds
    public float returnToCentreSpeed = 3; // The speed at which the button will return to its centre

    AxisTouchButton m_PairedWith; // Which button this one is paired with
    CrossPlatformInputManager.VirtualAxis m_Axis; // A reference to the virtual axis as it is in the cross platform input

    void OnEnable()
    {
    if (!CrossPlatformInputManager.AxisExists(axisName))
    {
    // if the axis doesnt exist create a new one in cross platform input
    m_Axis = new CrossPlatformInputManager.VirtualAxis(axisName);
    CrossPlatformInputManager.RegisterVirtualAxis(m_Axis);
    }
    else
    {
    m_Axis = CrossPlatformInputManager.VirtualAxisReference(axisName);
    }
    FindPairedButton();
    }

    void FindPairedButton()
    {
    // find the other button witch which this button should be paired
    // (it should have the same axisName)
    var otherAxisButtons = FindObjectsOfType(typeof(AxisTouchButton)) as AxisTouchButton[];

    if (otherAxisButtons != null)
    {
    for (int i = 0; i < otherAxisButtons.Length; i++)
    {
    if (otherAxisButtons.axisName == axisName && otherAxisButtons != this)
    {
    m_PairedWith = otherAxisButtons;
    }
    }
    }
    }

    void OnDisable()
    {
    // The object is disabled so remove it from the cross platform input system
    m_Axis.Remove();
    }


    public void OnPointerDown(PointerEventData data)
    {
    if (m_PairedWith == null)
    {
    FindPairedButton();
    }
    // update the axis and record that the button has been pressed this frame
    m_Axis.Update(Mathf.MoveTowards(m_Axis.GetValue, axisValue, responseSpeed * Time.deltaTime));
    }


    public void OnPointerUp(PointerEventData data)
    {
    m_Axis.Update(Mathf.MoveTowards(m_Axis.GetValue, 0, responseSpeed * Time.deltaTime));
    }
    }
    }

    Note: It's from the asset store
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. halojman

    halojman

    Joined:
    Sep 28, 2015
    Posts:
    27
    Code (JavaScript):
    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.EventSystems;
    4. using UnitySampleAssets.CrossPlatformInput;
    5.  
    6. namespace UnityStandardAssets.CrossPlatformInput
    7. {
    8.     public class AxisTouchButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
    9.     {
    10.         // designed to work in a pair with another axis touch button
    11.         // (typically with one having -1 and one having 1 axisValues)
    12.         public string axisName = "Horizontal"; // The name of the axis
    13.         public float axisValue = 1; // The axis that the value has
    14.         public float responseSpeed = 3; // The speed at which the axis touch button responds
    15.         public float returnToCentreSpeed = 3; // The speed at which the button will return to its centre
    16.  
    17.         AxisTouchButton m_PairedWith; // Which button this one is paired with
    18.         CrossPlatformInputManager.VirtualAxis m_Axis; // A reference to the virtual axis as it is in the cross platform input
    19.  
    20.         void OnEnable()
    21.         {
    22.             if (!CrossPlatformInputManager.AxisExsists(axisName))
    23.             {
    24.                 // if the axis doesnt exist create a new one in cross platform input
    25.                 m_Axis = new CrossPlatformInputManager.VirtualAxis(axisName);
    26.                 CrossPlatformInputManager.RegisterVirtualAxis(m_Axis);
    27.             }
    28.             else
    29.             {
    30.                 m_Axis = CrossPlatformInputManager.VirtualAxisReference(axisName);
    31.             }
    32.             FindPairedButton();
    33.         }
    34.  
    35.         void FindPairedButton()
    36.         {
    37.             // find the other button witch which this button should be paired
    38.             // (it should have the same axisName)
    39.             var otherAxisButtons = FindObjectsOfType(typeof(AxisTouchButton)) as AxisTouchButton[];
    40.  
    41.             if (otherAxisButtons != null)
    42.             {
    43.                 for (int i = 0; i < otherAxisButtons.Length; i++)
    44.                 {
    45.                     if (otherAxisButtons[i].axisName == axisName && otherAxisButtons[i] != this)
    46.                     {
    47.                         m_PairedWith = otherAxisButtons[i];
    48.                     }
    49.                 }
    50.             }
    51.         }
    52.  
    53.         void OnDisable()
    54.         {
    55.             // The object is disabled so remove it from the cross platform input system
    56.             m_Axis.Remove();
    57.         }
    58.  
    59.  
    60.         public void OnPointerDown(PointerEventData data)
    61.         {
    62.             if (m_PairedWith == null)
    63.             {
    64.                 FindPairedButton();
    65.             }
    66.             // update the axis and record that the button has been pressed this frame
    67.             m_Axis.Update(Mathf.MoveTowards(m_Axis.GetValue, axisValue, responseSpeed * Time.deltaTime));
    68.         }
    69.  
    70.  
    71.         public void OnPointerUp(PointerEventData data)
    72.         {
    73.             m_Axis.Update(Mathf.MoveTowards(m_Axis.GetValue, 0, responseSpeed * Time.deltaTime));
    74.         }
    75.     }
    76. }