Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jaqal · Jul 30, 2014 at 03:18 AM · collidercallfootsteps

How to call function from this script?

As the title suggests I am trying to call a function from another script in my footstep manager script. I am trying to activate a sphere collider everytime I take a step to simulate sounds that can be heard by enemies. I have already figured out where to do this and have a Debug.Log displaying for every step. I typically code in js so I am having alot of trouble with this. I have tried adding my sphere collider to a variable at the top of the script but it will never show in the inspector for some reason. I obviously did not write this code it was part of a package I own but any help would be greatly appreciated.

It is at line 136 under protected virtual void Footstep()

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class vp_FootstepManager : MonoBehaviour
 {
     public GameObject myCollider;
     /// <summary>
     /// surface type object for storing sounds in relation to textures
     /// </summary>
     [System.Serializable]
     public class vp_SurfaceTypes
     {
         public Vector2 RandomPitch = new Vector2( 1.0f, 1.5f ); // random pitch range for footsteps
         public bool Foldout = true; // used by the editor to allow folding this surface type
         public bool SoundsFoldout = true; // used by the editor to allow folding the sounds section
         public bool TexturesFoldout = true; // used by the editor to allow folding the textures section
         public string SurfaceName = ""; // Name of the surface for reference in the editor
         public List<AudioClip> Sounds = new List<AudioClip>(); // List of sounds to play randomly
         public List<Texture> Textures = new List<Texture>(); // list of the textures for this surface
 
     }
     
     static vp_FootstepManager[] m_FootstepManagers;
     public static bool mIsDirty = true;
     /// <summary>
     /// Retrieves the list of item databases, finding all instances if necessary.
     /// </summary>
 
     static public vp_FootstepManager[] FootstepManagers
     {
         get
         {
             if (mIsDirty)
             {
                 mIsDirty = false;
                 
                 m_FootstepManagers = GameObject.FindObjectsOfType(typeof(vp_FootstepManager)) as vp_FootstepManager[];
                 
                 // Alternative method, considers prefabs:
                 if(m_FootstepManagers == null)
                     m_FootstepManagers = Resources.FindObjectsOfTypeAll(typeof(vp_FootstepManager)) as vp_FootstepManager[];
             }
             return m_FootstepManagers;
         }
     }
     
     public List<vp_SurfaceTypes> SurfaceTypes = new List<vp_SurfaceTypes>(); // list of all the surfaces created
     public bool IsDirty{ get{ return mIsDirty; } }
     
     protected vp_FPPlayerEventHandler m_Player = null;        // for caching the player
     protected vp_FPCamera m_Camera = null;                    // for caching the FPCamera
     protected vp_FPController m_Controller = null;            // for caching the FPController
     protected AudioSource m_Audio = null;                    // for caching the audio component
     protected AudioClip m_SoundToPlay = null;                // the current sound to be played
     protected AudioClip m_LastPlayedSound = null;            // used to make sure we don't place the same sound twice in a row
     
     
     /// <summary>
     /// cache all the necessary properties here
     /// </summary>
     protected virtual void Awake()
     {
         
         m_Player = transform.root.GetComponentInChildren<vp_FPPlayerEventHandler>();
         m_Camera = transform.root.GetComponentInChildren<vp_FPCamera>();
         m_Controller = transform.root.GetComponentInChildren<vp_FPController>();
         m_Audio = gameObject.AddComponent<AudioSource>(); // add a new audio source for this class to use
     }
     
     
     public virtual void SetDirty( bool dirty )
     {
         mIsDirty = dirty;
     }
     
     
     /// <summary>
     /// 
     /// </summary>
     void Update()
     {
 
         // if the camera bob step callback is null for some reason,
         // add our footstep callback again
         if (m_Camera.BobStepCallback == null)
             m_Camera.BobStepCallback += Footstep;
 
     }
     
     
     /// <summary>
     /// 
     /// </summary>
     protected virtual void OnEnable()
     {
         
         // add the footstep callback
         m_Camera.BobStepCallback += Footstep;
         
     }
     
     
     /// <summary>
     /// 
     /// </summary>
     protected virtual void OnDisable()
     {
         
         // remove the footstep callback
         m_Camera.BobStepCallback -= Footstep;
         
     }
     
     
     /// <summary>
     /// Here is where we check to see if the texture
     /// under the controller is assigned to a surface.
     /// If so, play a sound.
     /// </summary>
     protected virtual void Footstep()
     {
         Debug.Log ("FootStep");
   
         // return if the controller is not on the ground
         if(!m_Controller.Grounded)
             return;
         
         // return if there no texture or surface type is found
         if(m_Player.GroundTexture.Get() == null && m_Player.SurfaceType.Get() == null)
             return;
         
         if(m_Player.SurfaceType.Get() != null)
         {    
             PlaySound( SurfaceTypes[ m_Player.SurfaceType.Get().SurfaceID ] );
             return;
         }
         
         // loop through the surfaces
         foreach(vp_SurfaceTypes st in SurfaceTypes)
         {
             // loop through the surfaces textures
             foreach(Texture tex in st.Textures)
             {
                 // if the texture is the same as the ground texture...
                 if(tex == m_Player.GroundTexture.Get())
                 {
                     // play random surface sound
                     PlaySound( st );
                     break;
                 }
             }
         }
         
     }
     
     
     /// <summary>
     /// Plays a random sound from the surface the
     /// controller is currently over
     /// </summary>
     public virtual void PlaySound( vp_SurfaceTypes st )
     {
         // return if there are no sounds
         if(st.Sounds == null || st.Sounds.Count == 0)
             return;
         
         reroll:
         m_SoundToPlay = st.Sounds[Random.Range(0,st.Sounds.Count)]; // get a random sound
         
         // if the sound is null, return
         if(m_SoundToPlay == null)
             return;
         
         // if the sound was the last sound played, reroll for another sound
         if (m_SoundToPlay == m_LastPlayedSound && st.Sounds.Count > 1)
             goto reroll;
         
         // set a random pitch
         m_Audio.pitch = Random.Range(st.RandomPitch.x, st.RandomPitch.y) * Time.timeScale;
         m_Audio.clip = m_SoundToPlay;
         m_Audio.Play(); // play the sound
         m_LastPlayedSound = m_SoundToPlay; // cache this sound
         
     }
     
     
     /// <summary>
     /// Returns the zero-based index of the most dominant texture
     /// on the main terrain at this world position.
     /// </summary>
     public static int GetMainTerrainTexture(Vector3 worldPos, Terrain terrain)
     {
         
         TerrainData terrainData = terrain.terrainData;
         Vector3 terrainPos = terrain.transform.position;
  
         // calculate which splat map cell the worldPos falls within (ignoring y)
         int mapX = (int)(((worldPos.x - terrainPos.x) / terrainData.size.x) * terrainData.alphamapWidth);
         int mapZ = (int)(((worldPos.z - terrainPos.z) / terrainData.size.z) * terrainData.alphamapHeight);
  
         // get the splat data for this cell as a 1x1xN 3d array (where N = number of textures)
         float[,,] splatmapData = terrainData.GetAlphamaps(mapX,mapZ,1,1);
  
         // extract the 3D array data to a 1D array:
         float[] mix = new float[splatmapData.GetUpperBound(2)+1];
         for (int n=0; n<mix.Length; ++n)
         {
             mix[n] = splatmapData[0,0,n];    
         }
   
         float maxMix = 0;
         int maxIndex = 0;
  
         // loop through each mix value and find the maximum
         for (int n=0; n<mix.Length; ++n)
         {
             if (mix[n] > maxMix)
             {
                 maxIndex = n;
                 maxMix = mix[n];
             }
         }
  
         return maxIndex;
  
     }
     
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Jaqal · Aug 27, 2014 at 08:10 PM

So the problem I had with this was all of my other scripts are in js and this is in c#. In order to communicate between js and c# one or the has to compile first. The best way to do this is the scripts you want to compile first into the standard assets folder or plugins folder. Works fine now.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Footstep Script Not Working 2 Answers

Convert "SHIFT" button for running to Mobile? 1 Answer

Terrain with lots of objects 1 Answer

Is there any way for a script to get its caller? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges