Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - ramunda

#16
Buenas noches , tengo un dilema con una bola de un juego tipo "arkanoid" que estoy montando.
 
Todo va bien excepto cuando la bola vuelve a la plataforma , allí deberían resetearse las fisicas que le aplico en el start.
 
Para ello uso la función de el Rigidbody2D y lo pongo en kinematico, creía que con esto bastaria....pero no , cada vez que renace la bola va mas rápida, evidentemente esta duplicando la fuerza asignada en el start....pero no se porque!
 
Espero que puedan ayudar.
 
Alla va el script:
 
 
 

using UnityEngine;
using System.Collections;
public class BallScript : MonoBehaviour {
private bool ballIsActive;
private Vector3 ballPosition;
private Vector2 ballInitialForce;
public GameObject playerObject;
public AudioClip hitSound;
AudioSource audio;
private Rigidbody2D rb;
void Start ()
{
   rb = GetComponent<Rigidbody2D>();
   ballIsActive = false;
   ballInitialForce = new Vector2 (50.0f,300.0f);
   ballPosition = transform.position;
   audio=GetComponent<AudioSource>();
}
 
void Update ()
{
   
   if (Input.GetButtonDown ("Jump") == true)
   {
      
      if (!ballIsActive)
      {
         ///reseteamos la fuerza?
         rb.isKinematic = false;
         rb.AddForce (ballInitialForce);
         ballIsActive = !ballIsActive;
      }
   }
   if (!ballIsActive && playerObject != null)
   {
           ballPosition.x = playerObject.transform.position.x;
      transform.position = ballPosition;
   }
}
   
void OnCollisionEnter2D(Collision2D collision)
{
   if (ballIsActive)
   {
      audio.PlayOneShot (hitSound);
}
   if (collision.gameObject.tag == "mata")
   {
      if (ballIsActive)
      {   
         
         Debug.Log ("muere");
         ballIsActive = !ballIsActive;
         ballPosition.x = playerObject.transform.position.x;
         ballPosition.y = -4.5f;
         transform.position = ballPosition;
         rb.isKinematic = true;
         playerObject.SendMessage ("TakeLife");
      }
   }
}
}
   
 

 
 
#17
Cita de: James Roman date=1503115351el else que llama a la coroutine quitavida deberia estar justo despues del if(hit.collider != null), es decir el funcionamiento de tu codigo actual es que en cada frame si no haces click te va a quitar una vida en 6 seg, imagino que el jugador no logra vivir mas que eso ya que cada frame llama una nueva?, y aun que hagas lo que te he dicho puedes tener errores ya que imagino que tendras diferentes elementos en el juego si clickeas por error en algun elemento X con collider y no es el granjero igual no perderas ninguna vida, te recomiendo usar la version de raycast que utiliza layerMask colocar al granjero en su propia layer y asi de esta manera ignoras los otros elementos que puedan existir.
   


muchisimas gracias James Roman , tienes toda la razon , como no lo abia visto...muy amable.Un saludo cordial.
#18
Buenas tardes,
 
Tengo un pequeño dilema y no se porque no funciona, seguramente es una tontería pero llevo 2 horas comiéndome la cabeza y no logro encontrar el porque!
 
Tengo un script desde donde controlo las cosas."GameControl";
 

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameControl : MonoBehaviour
{
public static GameControl instance;         //referencia del gamee control script que podemos acceder instantaneamente.
public Text scoreText;                  
private int puntos = ;                  
public bool gameOver = false;            
public float scrollSpeed = -1.5f;
public GameObject gameoverr;
public int vidas =;
public Text vidasText;   
 
void Awake()
{
   //si no tenemos el  control...
   if (instance == null)
      //...lo llamamos...
      instance = this;
   //...de lo contrario...
   else if(instance != this)
   //...destruye este porque esta duplicado.
      Destroy (gameObject);
}
void Start()
{
   gameoverr.SetActive (false);
   PlayerPrefs.SetInt ("MyScore",);
   //PlayerPrefs.SetInt ("vidas",0);
   vidasText.text = "Lives: " + vidas.ToString();
}
void Update()
{
   if (vidas <= )
   BirdDied ();
}
public void BirdScored()
{
//      //si el player no puede hacer mas puntos y acabo la partida.
   if (gameOver)   
   return;
   //si el juego no ha terminado, aumentamos el score...
   puntos += 1;
   //...i lo mostramos en el score.
   PlayerPrefs.SetInt ("MyScore", puntos);
   scoreText.text = "Score: " + puntos.ToString();
   vidasText.text = "Lives: " + vidas.ToString();
}
public void BirdDied()
{
   //Activa el gameover.
   gameOver = true;
   gameoverr.SetActive (true);
   PlayerPrefs.GetInt ("MyScore");
}
public void quitavida()
{
   vidas -= 1;
}
}

 
y tengo este otro que registra  un raycast que si no colisiona con el gametag granjero hace una animación y después destruye el GO.
 
Hasta aqui bien la cosa viene cuando le quiero decir que si no has clickado encima de el GO,con el tag " granjero", que se active el sistema de quitar una vida pasados 6 segundos, para eso llamo  a la coorutina quitavida, la cual espera 6 segundos e instancia el void quitavid que se encuentra en el script anterior.Pero no hace tal cosa!
 
este es el script ;
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class tocagranjero : MonoBehaviour
{
private Animator anim;   
private Rigidbody2D rb2d;   
private GameObject gamecontrol;
public AudioSource audio2;
AudioSource audio;
 
void Start()
{
   anim = GetComponent<Animator> ();
   rb2d = GetComponent<Rigidbody2D>();
   audio = GetComponent<AudioSource> ();
   gamecontrol = GameObject.Find ("GameControl");
 
}
IEnumerator quitavida()
{
   yield return new WaitForSeconds(6);
   GameControl.instance.quitavida ();
   Debug.Log ("te quito una vida");
}
void Update ()
{
   if (Input.GetMouseButtonDown ())
   {
      Vector3 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
      Vector2 mousePos2D = new Vector2 (mousePos.x, mousePos.y);
      RaycastHit2D hit = Physics2D.Raycast (mousePos2D, Vector2.zero);
      if (hit.collider != null)
      {
         Debug.Log (hit.collider.gameObject.name);
         if (hit.collider.tag == "granjero")
         {
         anim.SetTrigger ("tocado");
         GameControl.instance.BirdScored ();
         Destroy (hit.transform.gameObject, 2);
         audio2.Play ();
         }
      }
   }
   else
   {  
   StartCoroutine ("quitavida");
   }
}
}

 
Espero que sea lo que digo una tontería....y que alguno de ustedes pueda decírmela, muchas gracias de antemano.
 
 
 
 
 
 
#19
Cita de: ramunda date=1499883378Buenas tardes, tengo que terminar un dichoso proyecto de la uni i me veo que no lo terminare a menos q
   


muchas gracias kaulua66 , ya estoy en ello.
 
Un saludo!
#20
Buenas tardes, tengo que terminar un dichoso proyecto de la uni i me veo que no lo terminare a menos que me puedan echar un cable.
 
Veamos necesito mandar el valor de este int(ver script mas abajo), a un archivo php ( http://adisfrutar/prova.php?  )
 
pero he foreado mucho i no saco nada en claro.
 
alguna idea por favor?
 
 
 
aqui el script de el score:
 
 
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class score : MonoBehaviour
{
AudioSource audio;
int puntos = ;
public Text puntuacion;
public Animation anim;
void Start()
{
   audio = GetComponent<AudioSource>();
}
void OnTriggerEnter(Collider c)
{
   if (c.gameObject.tag == "coin") {  
      puntos += 10; // add your own score
      audio.Play ();
      if (PlayerPrefs.GetInt ("MyScore") < puntos)
      PlayerPrefs.SetInt ("MyScore", puntos);
      puntuacion.text = "Puntos: " + puntos.ToString ();
      Destroy (c.gameObject);
   }

}
}

 
 
#21
Muchisimas gracias #lighbug , va de lujo asi queda el script final para futuras referemcias :)
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class quitaflechas : MonoBehaviour
{
public List<GameObject> enemies;
void Awake()
{
   enemies = new List<GameObject>();
   foreach(GameObject enemy in GameObject.FindGameObjectsWithTag("flecha"))
   {
      enemies.Add(enemy);    
   }
}
void Update()
{
 
      if (Input.GetButtonDown ("Fire1"))
       {
      if(enemies.Count > )
      {
         enemies [].SetActive(false); //aca le haces lo que quieras
         enemies.RemoveAt();
      }
      }

 
Gracias!!
#22
Buenos dias.
 
Tengo una simple lista de objetos(flechas),el cual cuando aprieto la barra espaciadora va quitando uno a uno las flechas de la lista.
 
Esto va perfecto.Pero mi intención es que también me los quite visualmente osea desde el juego con un disable/delete lo que sea.
 
Pero no veo la manera.
 
Agradecería una ayuda.
 
Gracias
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class quitaflechas : MonoBehaviour
{
public List<GameObject> enemies;
void Awake()
{
   enemies = new List<GameObject>();
   foreach(GameObject enemy in GameObject.FindGameObjectsWithTag("flecha"))
   {
      enemies.Add (enemy);    
   }
}
void Update()
{
   if(enemies.Count > )
   {
      if(Input.GetKeyDown (KeyCode.Space))
      {
         enemies.RemoveAt();
         print (enemies.Count);
      }
   }
}
}

 
 
 
 
#23
General (Antiguo) / Disparo enemigo(resuelto).
Junio 02, 2017, 12:33:20 AM
Bueno ....el tema esta solucionado.Gracias a  #GSG3D, he creado un timer el cual espera el tiempo para que instancie de nuevo el prefab.
 
Ha quedado asi, lo pongo funcionado para posibles lecturas.
 
Muchas gracias.
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemigoataca : MonoBehaviour {
private Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxRange;
public int minRange;
public GameObject bulletPrefab;
public Transform bulletSpawn;
//public float speed;
AudioSource audio;
bool dispaross=false;
private float nextFire = 0.0F;
public float fireRate = 0.5F;
private Transform myTransform;
void Awake()
{
   myTransform = transform;
}
void Start ()
{
   GameObject go = GameObject.FindGameObjectWithTag("Player");
   target = go.transform;
}
 
void Update ()
{
   Debug.DrawLine(target.position, myTransform.position, Color.yellow);
   //mir al player
   myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
   if ((Vector3.Distance (transform.position, target.position) < maxRange) && (Vector3.Distance (transform.position, target.position) > minRange) && Time.time >nextFire)
   {
      transform.LookAt (target);
      transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime);
      Fire();
   }
}
void Fire()
{
   nextFire = Time.time + fireRate;
   var bullet = (GameObject)Instantiate (bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);
   Destroy(bullet, 2f);
}
}

 
 
#24
General (Antiguo) / Disparo enemigo(resuelto).
Junio 01, 2017, 11:48:44 PM
Cita de: GSG3D date=1496353348Seguramente la llamada a la funcion
   
   

Invoke("Fire",3);

   
      la estas ejecutando continuamente por el Update, porque el condicional es verdadero.

      Pon un Debug.Log dentro del condicional y mira si es asi.
   
   
       
   


si , asi es se repite constantemente.
 
aver si puedo hacer una coorutina.
 
he probado asi, en este caso esta fuera de el update, pero sigue sin funcionar.
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemigoataca : MonoBehaviour {
private Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxRange;
public int minRange;
public GameObject bulletPrefab;
public Transform bulletSpawn;
public float speed;
AudioSource audio;
private Transform myTransform;
void Awake()
{
   myTransform = transform;
}
IEnumerator disparos()
{
   yield return new WaitForSeconds (10);
   Fire ();
}

   
void Start ()
{
   GameObject go = GameObject.FindGameObjectWithTag("Player");
   target = go.transform;
}
 
void Update ()
{
   Debug.DrawLine(target.position, myTransform.position, Color.yellow);
   //Look at target
   myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
   if ((Vector3.Distance (transform.position, target.position) < maxRange) && (Vector3.Distance (transform.position, target.position) > minRange))
   {
      transform.LookAt (target);
      transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime);
      StartCoroutine("disparos");
      Debug.Log ("disparo");
   }
}
void Fire()
{
   var bullet = (GameObject)Instantiate (bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);
   Destroy(bullet, 2f);
}
}
 


 
 
 
 
#25
General (Antiguo) / Disparo enemigo(resuelto).
Junio 01, 2017, 10:36:48 PM
Buenas noches , tengo un pequeño problema con un disparo que me realiza un enemigo.
 
En este caso es una nave enemiga que al estar en un rango de alcance, me dispara. hasta aquí todo esta bien.
 
El problema viene cuando instancio el láser que me dispara el enemigo....intento que me dispare en intervalos osea que salga por ejemplo 1 laser cada segundo pero me saca 300 lasers seguidos y en linea!!
 
no veo donde fallo para que solo dispare un laser cada por ejemplo 1 segundo.
 
Este es el script:
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemigoataca : MonoBehaviour {
private Transform target;
public int moveSpeed;
public int rotationSpeed;
public int maxRange;
public int minRange;
public GameObject bulletPrefab;
public Transform bulletSpawn;
public float speed;
AudioSource audio;
bool disparo =false;
public float tiempodisparo =0.5f;
private float nextFire =0.0f;
 
private Transform myTransform;
void Awake()
{
   myTransform = transform;
}
void Start ()
{
   GameObject go = GameObject.FindGameObjectWithTag("Player");
   target = go.transform;
}
 
void Update ()
{
   Debug.DrawLine(target.position, myTransform.position, Color.yellow);
   //Look at target
   myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
   if ((Vector3.Distance (transform.position, target.position) < maxRange) && (Vector3.Distance (transform.position, target.position) > minRange))
   {
      transform.LookAt (target);
      transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime);
      Invoke("Fire",3);
   }
}
void Fire()
{
       nextFire = Time.time + tiempodisparo;
   var bullet = (GameObject)Instantiate (bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);
       Destroy(bullet, 0.3f);
}
}
 
 

 
Agradecería una ayuda o idea, gracias de antemano!!!
 
 
 
 
 
 
 
 
#26
General (Antiguo) / Trigger exit audio
Abril 22, 2017, 07:08:56 PM
Muchas gracias por la pronta respuesta lightbug, ya lo habia intentado con bool pero lo esta estructurando mal ahora veo la manera correcta ,muchas gracias!!
 
 
#27
General (Antiguo) / Trigger exit audio
Abril 22, 2017, 06:51:45 PM
Buenas tardes , tengo un simple script que al entrar en un trigger empiexa a sonar una musica y quiero que al salir se detenga bajando el volumen.
 
No me da error , y suena al entrar...pero no disminuye al salir como yo esperaba.
 
El debug lo marca bien , osea que detecta al jugador al salir.
 
Alguna idea por favor?
 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class activaenemigos : MonoBehaviour {
private GameObject player;
public GameObject enemigos;
private GameObject cameramain;
private GameObject cameraenemiga;
float audioVolume;
AudioSource audio;
void Start ()
{
enemigos.SetActive (false);
player = GameObject.FindWithTag ("Player");
audio = GetComponent<AudioSource>();
}
void OnTriggerEnter (Collider col)
{
   if (col.tag == "Player")
   {  
      enemigos.SetActive (true);
      audio.Play ();
   }
}
void OnTriggerExit (Collider col)
{
   Debug.Log ("salida");
   if (audio.volume > 0.09)
   {
      audio.volume -= 0.1f * Time.deltaTime;
   }   
        Invoke ("desactivalos",5);
}
void Update()
{
   if (player.GetComponent<vidajugador> ().curHealth < )
   {
      if (audio.volume > 0.09)
      {
         audio.volume -= 0.1f * Time.deltaTime;
      }
      Invoke ("desactivalos",16);
   }
}
void desactivalos()
{
    enemigos.SetActive (false);
   if (audio.volume > 0.09)
   {
      audio.volume -= 0.1f * Time.deltaTime;
   }
}
}

 
Gracias
#28
General (Antiguo) / Distancia de objetos
Marzo 19, 2017, 02:48:49 PM
Buenas tardes,
 
Tengo una duda y quiero preguntarles:
 
Tengo un sencillo sistema de paga para mi juego el cual simplemente me muestra en una textura de radar los enemigos y los busca por tag,
 
Esto funciona perfectamente el problema viene en la distancia en que los detecta.
 
por mucho que le suba la public float no aumenta la distancia en que me aparecen en el radar y no se el motivo....
 
Allá va el script:
 

using UnityEngine;
using HWRcomponent;
using System.Collections;
 
namespace HWRcomponent
{
public enum Alignment
{
   None,
   LeftTop,
   RightTop,
   LeftBot,
   RightBot ,
   MiddleTop ,
   MiddleBot
}
}
public class RadarSystem : MonoBehaviour
{
private Vector2 inposition;
public float Size = 400; //  tamaño e el mapa
public float Distance = ;// distania maxima de los objetos
public float Transparency = 0.5f;// transparencia de lso objetos
public Texture2D[] Navtexture;// lista de texturs
public string[] EnemyTag;// lista de tags de los objetos
public Texture2D NavCompass;// textura de el compas
public Texture2D CompassBackground;// textura de el fondo
public Vector2 PositionOffset = new Vector2 (, );// posición de el minimapa
public float Scale = 1;// escala de el minimapa
public Alignment PositionAlignment = Alignment.None;// alineamiento
public bool MapRotation;
public GameObject Player;
public bool Show = true;
public Color ColorMult = Color.white;

void Start ()
{

}
void Update ()
{
   if (!Player) {
      Player = this.gameObject;
   }
   
   if (Scale <= ) {
      Scale = 100;
   }
   // define la posición
   switch (PositionAlignment) {
   case Alignment.None:
      inposition = PositionOffset;
      break;
   case Alignment.LeftTop:
      inposition = Vector2.zero + PositionOffset;
      break;
   case Alignment.RightTop:
      inposition = new Vector2 (Screen.width - Size, ) + PositionOffset;
      break;
   case Alignment.LeftBot:
      inposition = new Vector2 (, Screen.height - Size) + PositionOffset;
      break;
   case Alignment.RightBot:
      inposition = new Vector2 (Screen.width - Size, Screen.height - Size) + PositionOffset;
      break;
   case Alignment.MiddleTop:
      inposition = new Vector2 ((Screen.width / 2) - (Size / 2), Size) + PositionOffset;
      break;
   case Alignment.MiddleBot:
      inposition = new Vector2 ((Screen.width / 2) - (Size / 2), Screen.height - Size) + PositionOffset;
      break;
   }
   
}
Vector2 ConvertToNavPosition (Vector3 pos)
{
   Vector2 res = Vector2.zero;
   if (Player) {
      res.x = inposition.x + (((pos.x - Player.transform.position.x) + (Size * Scale) / 2f) / Scale);
      res.y = inposition.y + ((-(pos.z - Player.transform.position.z) + (Size * Scale) / 2f) / Scale);
   }
   return res;
}
void DrawNav (GameObject[] enemylists, Texture2D navtexture)
{
   if (Player) {
      for (int i=; i<enemylists.Length; i++) {
         if (Vector3.Distance (Player.transform.position, enemylists [i].transform.position) <= (Distance * Scale)) {
            Vector2 pos = ConvertToNavPosition (enemylists [i].transform.position);
         
            if (Vector2.Distance (pos, (inposition + new Vector2 (Size / 2f, Size / 2f))) + (navtexture.width / 2) < (Size / 2f)) {
               float navscale = Scale;
               if (navscale < 1) {
                  navscale = 1;
               }
               GUI.DrawTexture (new Rect (pos.x - (navtexture.width / navscale) / 2, pos.y - (navtexture.height / navscale) / 2, navtexture.width / navscale, navtexture.height / navscale), navtexture);
            }
         }
      }
   }
}
float[] list;
void OnGUI ()
{
   if (!Show)
      return;
   
   GUI.color = new Color (ColorMult.r, ColorMult.g, ColorMult.b, Transparency);
   if (MapRotation) {
      GUIUtility.RotateAroundPivot (-(this.transform.eulerAngles.y), inposition + new Vector2 (Size / 2f, Size / 2f));
   }

   for (int i=; i<EnemyTag.Length; i++) {
      DrawNav (GameObject.FindGameObjectsWithTag (EnemyTag [i]), Navtexture [i]);
   }
   if (CompassBackground)
      GUI.DrawTexture (new Rect (inposition.x, inposition.y, Size, Size), CompassBackground);
   GUIUtility.RotateAroundPivot ((this.transform.eulerAngles.y), inposition + new Vector2 (Size / 2f, Size / 2f));
   if (NavCompass)
      GUI.DrawTexture (new Rect (inposition.x + (Size / 2f) - (NavCompass.width / 2f), inposition.y + (Size / 2f) - (NavCompass.height / 2f), NavCompass.width, NavCompass.height), NavCompass);
}
}

 
 
 
Linea 26: public float Distance 0 ;
 
Gracias.
 
 
 
 
 
 
 
 
#29
Cita de: gomeslaw date=1489162099Yo creo que lo tienes en esta linea:
   
   

if (audio.pitch >= acelera)

   
      Cuando audio.pitch es menor que acelera(1f), entra en el if y le resta :
   
   

audio.pitch -= decelera *Time.deltaTime;

   
       
   
   
      En ese momento audio.pitch es 0.99, y la condicion del  if no se cumple, por eso no te lo resta mas. Supongo que tendrias que sustituir acelera por decelera.
   
   
       
   
   
      Saludos
   


Pero que tonto soy...tienes toda la razón del mundo.
 
Funciona perfectamente con tu explicación que ademas es muy detallada y bien explicada.
 
Muchisimas gracias!!
 
Un abrazo.
#30
Buenas tardes,
 
Tengo una duda y no se porque no la puedo solucionar....
 
Tengo un barco que al estar parado/relenti , el sonido es de bajas revoluciones.
 
Al acelerar acelero el pitch de el audioclip(eso funciona no me hace el Time.deltatime) pero funciona.
 
El problema viene cuando decelero.
 
El sonido baja el pitch pero no al numero que yo le doy, solo una coma por debajo.
 
Expongo el scrip asi lo entienden mejor:;
 

using System.Collections;
using UnityEngine;
    public class controlbarco : MonoBehaviour {

public float velocidadgiro = 50f;
public float marcha =50f;
AudioSource audio;
private Rigidbody rb;
public GameObject espuma;
public float decelera = 0.49f;
public float acelera = 1f;
 
void Start()
{
   rb = GetComponent<Rigidbody>();
   espuma.SetActive(false);
   audio = GetComponent<AudioSource>();
   audio.pitch = decelera;
}
void FixedUpdate ()
{
   
   float h = Input.GetAxis ("Horizontal") * velocidadgiro * Time.deltaTime;
   float v = Input.GetAxis ("gatilloderecha") * marcha * Time.deltaTime;
   rb.AddTorque (transform.up * h);
   rb.velocity = transform.forward * v;
            
   if (v >= 0.1f) {
      espuma.SetActive (true);
      if (audio.pitch <= 1f) {      
      audio.pitch += acelera * Time.deltaTime;
      }
   }
   
   if (v <= 0.1f) {
   if (audio.pitch >= acelera)
   {      
   audio.pitch -= decelera *Time.deltaTime;
   Invoke ("paraespumas", 2);
   }
   }
   Debug.Log("Velocity: " + rb.velocity + "//Variable V " + v);
    }
   void paraespumas()
   {
   espuma.SetActive (false);
   {      
   }
   }
}

 
los floats publicos los tengo en :
 
Acelera 1
 
Decelera 0.49
 
El acelera va bien (se pone a 1), porque en el start le tengo que el pitch este en el valor de decelera.
 
El decelera se queda a: 0.99 en vez de los -0.49 que debería quedar.
 
Donde lo estoy haciendo mal?
 
 
 
Muchas gracias por adelantado.