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ú

Temas - ramunda

#21
General (Antiguo) / Tengo un pequeño lio....
Agosto 26, 2016, 05:23:40 PM
Buenas tardes,
 
tengo un pequeño lío.
 
Tengo un Scoremanager donde controlo todas las puntuaciones de los objetos por ejemplo un bumper.
 
Cojo los valores desde alli asi me es mas fácil cambiarlos globalmente.
 
Pero nose que he liado....y ahora no veo la luz, estoy atascado.
 
Este script es el maestro:
 

using UnityEngine;
using System.Collections;
public class ScoreManager : MonoBehaviour
{
public static ScoreManager Instance;
void Awake()
{
Instance = this;
}
public   int score =;
public   int scorebumper =50000;
public   int scoredianas =100;
public   int scoreagujeros =10000;
public   int scoretarjets =100;
public   int scorePower = 1;
public   int bankvalue =10000;
public    TextMesh display;
void Update()
{
   if (display)
   {
      display.text = score.ToString ("D8");
   }
}
public   void ScoreUp(int points)
{
score += (points * scorePower);
}
public  void SetScorePower(int power)
{
   scorePower = power;
}
}
 

 
Bien desde aqui controlo casi todo...
 
Ahora el objeto que me da puntos por ejemplo el bumper.:
 

using UnityEngine;
using System.Collections;
public class Bumper : MonoBehaviour {
public float force = 100.0f;
public float forceRadius = 1.0f;
public int scoreValue= 100;
public GameObject spotlight;
public AudioClip bumpersound;
AudioSource audio;
public  GameObject TextOnSpotGO;
 
 
void Start ()
{
   audio = GetComponent<AudioSource> ();
}

void OnCollisionEnter()
{
   foreach(Collider col in Physics.OverlapSphere(transform.position, forceRadius))
   {
      if (col.GetComponent<Rigidbody> ())
      {  
         spotlight.SetActive (true);
         col.GetComponent<Rigidbody> ().AddExplosionForce (force, transform.position, forceRadius);
         audio.PlayOneShot (bumpersound, 0.7F);
      }
      else
      {
       Invoke ("apagado",01);
      }
   }
   ScoreManager.Instance.ScoreUp(scoreValue);
   Instantiate (TextOnSpotGO, transform.position, Quaternion.identity);
   TextOnSpotGO.GetComponent<TextOnSpotScript>().DisplayText = ScoreManager.Instance.scorebumper * ScoreManager.Instance.scorePower + "";
}
 
void apagado()
{
   
   spotlight.SetActive (false);
}
}

 
lineas 40 a 42.
 
en la 42 le digo que me coja los valores de Scoremanager y los digamos enseñe en un texto flotante en la pantalla.
 
El problema me viene que , en la linea 40:
 
ScoreManager.Instance.ScoreUp(scoreValue);
 
cojo el valor de scorevalue (linea8), para que se me sume al marcador (Scoremanager), pero lo que quiero es cojer el valor de scorebumper no el de scoremanager, y me estoy volviendo loco!!
 
Sera una tonteria pero me tiene saturado.
 
Agradeceria una ayuda por favor.
 
Gracias de antemano.
 
 
 
 
 
 
 
 
 
 
#22
Buenas tardes,
 
tengo un pequeño dilema que me lleva de cabeza, he buscado y remirado pero nada da en el clavo.
 
Tengo una puerta que se abre con una animación con un trigger, bien la animación abre la puerta ,
 
El caso es que quiero que se cierre la puerta cuando por ejemplo me matan o lo que sea.En este caso en cuando pierdo una bola.
 
Pues no hay manera. He probado con rewind, con -1 y +1 de todo ..la puerta no se cierra.
 
Os enseño como lo tengo aver si teneis alguna idea.
 
este la abre:
 

using UnityEngine;
using System.Collections;
public class x3 : MonoBehaviour {
public float force = 100.0f;
public float forceRadius = 1.0f;
public int scoreValue=100000;
public GameObject spotlight;
public AudioClip bumpersound;
public AudioClip puerta;
AudioSource audio;
public GameObject puerta3;
public GameObject luzx1;
public  GameObject TextOnSpotGO;
public GameObject light;
Animation anim;
// public GameObject puntacos;
void Start ()
{
   audio = GetComponent<AudioSource>();
   anim =puerta3.GetComponent<Animation> ();
   light.SetActive (false);
   spotlight.SetActive (false);
}
void OnTriggerEnter (Collider col)
{
   ScoreManager.Instance.SetScorePower (2);
   if(col.gameObject.name == "Ball")
   Instantiate (TextOnSpotGO, transform.position, Quaternion.identity);
   TextOnSpotGO.GetComponent<TextOnSpotScript>().DisplayText = ScoreManager.Instance.scoreagujeros * ScoreManager.Instance.scorePower + "";
   ScoreManager.Instance.ScoreUp(scoreValue);
   anim.Play ("Take001");
   Invoke ("apagado", 03);
      
}
void apagado()
{
   spotlight.SetActive(true);
   audio.PlayOneShot(bumpersound, 0.9F);
   light.SetActive (true);
   luzx1.SetActive (false);
   spotlight.SetActive (true);
}
}

 
Este debería cerrarla al perder una bola:
 

using UnityEngine;
using System.Collections;
public class BallManager : MonoBehaviour
{
public GameObject ball;
public Transform spawnPosition;
public TextMesh display;
public int lives = 3;
public bool gameOver = false;
AudioSource audio;
public GameObject luzx1;
public GameObject luzx2;
//public GameObject puerta1;
//public GameObject puerta2;
public GameObject puerta3;
Animation anim;
 
void Start()
{
   
   anim = GetComponent<Animation>();
   AudioSource audio = GetComponent<AudioSource> ();
}
   
void Update()
{
   //AudioSource audio = GetComponent<AudioSource> ();
   //Check for gameover
   if (lives < ) {
      if (display) {
         display.text = "GAME OVER";
         gameOver = true;
      }
   }
   
   //Ball cae y no es game over
   if (!GameObject.FindGameObjectWithTag ("Ball") && !gameOver) {
      lives--;
      Instantiate (ball, spawnPosition.position, ball.transform.rotation);
      audio.Play ();
      luzx1.SetActive (true);
      luzx2.SetActive (false);
      puerta3.GetComponent<Animation>() ["Take 001"].speed = -1;
      puerta3.GetComponent<Animation> () ["Take 001"].time = GetComponent<Animation> () ["Take 001"].length;
      puerta3.GetComponent<Animation> ().Play ("Take 001");
   

      //Update bolas restantes
      if(display)
      {
         display.text = "BOLAS RESTANTES: " + lives.ToString();
      }
   }
   
   //Reset game with return key if game is over
   if(gameOver)
   {
      if(Input.GetKeyDown(KeyCode.Return))
      {
         Application.LoadLevel(Application.loadedLevel);
      }
   
   }
}
}

 
Gracias de antemano.
 
 
 
 
#23
General (Antiguo) / Puntuación doble
Agosto 15, 2016, 01:54:10 PM
Buenas tardes , una pregunta por favor.
 
Estoy haciendo algo parecido a un pinball.
 
Bien la cosa es que quiero hacer que cuando se encienda un x2 o x4 la puntuación global de todo sea pos eso x2 x3.etc.
 
Tengo un simple script que recoge esta puntuación y los demás se basan en este pero no veo la manera de decirle un momento dado que me los multiplique por ejemplo mintras este encendido un botón o lo que sea.
 
mi script de puntuación es el siguiente:
 

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

public static int score = ;
public TextMesh display;
void Update()
{
   if (display)
   {
      display.text = score.ToString ("D8");
   }
}
}

 
 
 
Y este por ejemplo es el que uso para sumar puntos en uno de los objetos.
 

using UnityEngine;
using System.Collections;
public class Bumper : MonoBehaviour {
public float force = 100.0f;
public float forceRadius = 1.0f;
public int scoreValue = 100;
public GameObject spotlight;
public AudioClip bumpersound;
AudioSource audio;
void Start ()
{
   audio = GetComponent<AudioSource>();
}

void OnCollisionEnter()
{
   foreach(Collider col in Physics.OverlapSphere(transform.position, forceRadius))
   {
      if (col.GetComponent<Rigidbody> ()) {
         col.GetComponent<Rigidbody> ().AddExplosionForce (force, transform.position, forceRadius);
         spotlight.SetActive(true);
         audio.PlayOneShot(bumpersound, 0.7F);
      }
      else
      {
   Invoke ("apagado",01);
      }
   }
   ScoreManager.score += scoreValue;
}
 
void apagado()
{
   
   spotlight.SetActive (false);
}
}

 
Seguro que es algo sencillo pero no le veo ni pies ni cabeza.
 
Gracias de antemano.
 
 
 
 
#24
General (Antiguo) / no repetir audio
Agosto 09, 2016, 12:28:51 AM
Buenas noches, necesito una idea por favor:
 
Estoy haciendo un flipper, bien los Flippers osea las manecillas que golpean la bola, al activarse hacen un ruido, bien.
 
el ruido va perfecto excepto cuando mantengo el boton de el mouse para retener la bola, el sonido se repite.
 
He tenido en cuenta la opción de cambiar esto:(script completo mas abajo).
 

if(Input.GetButton(buttonName))

 
por esto
 

if(Input.GetButtonDown(buttonName))

 
Pero veréis que no es alternativa ya que utilizo Fuerza para moverlos y no funcionan en este caso.
 
Aqui el script completo:
 
 
 

using UnityEngine;
using System.Collections;
public class ApplyForceAtOffet : MonoBehaviour {
public float force = 100.0f;
public Vector3 forceDirection = Vector3.forward;
public string buttonName = "Fire1";
public Vector3 offset;
//public AudioClip flipersound;
AudioSource audio;
public AudioClip flipersound;
private bool detener;
   
void Update ()
{
if(Input.GetButton(buttonName))
{
audio = GetComponent<AudioSource>();
if (!audio.isPlaying)
fliper ();
GetComponent<Rigidbody>().AddForceAtPosition(forceDirection.normalized*force,transform.position+offset);
}
else
{
GetComponent<Rigidbody>().AddForceAtPosition(forceDirection.normalized*-force,transform.position+offset);
}
}
void fliper()
{
   detener = true;
   audio.clip = flipersound;
   audio.loop = false;
   //audio.PlayOneShot(flipersound, 0.7F);
   audio.Play();
   
}
}

 
Gracias de antemano.
 
 
 
 
#25
General (Antiguo) / Covertir Js a C#
Agosto 06, 2016, 04:43:13 PM
Buenas tardes
 
por favor , alguien que sepa tanto de c# como de Java me podria terminar de traducir este pequeño script?
 
:
 
He traducido casi todo ya que c# mas o menos lo controlo pero algo no he echo bien ya que me da errores en las últimas líneas;
 
El de JS es este:
 

#pragma strict
 
var restPosition : float = 0F;
var pressedPosition : float = 45F;
var flipperStrength : float = 10F;
var flipperDamper : float = 1F;
 
function Awake ()
{
GetComponent.<HingeJoint>().useSpring = true;
}
 
function Update ()
{
var spring : JointSpring = new JointSpring();

spring.spring = flipperStrength;
spring.damper = flipperDamper;

if (Input.GetButton("Fire1"))
   spring.targetPosition = pressedPosition;
else
   spring.targetPosition = restPosition;

GetComponent.<HingeJoint>().spring = spring;
GetComponent.<HingeJoint>().useLimits = true;
GetComponent.<HingeJoint>().limits.min = restPosition;
GetComponent.<HingeJoint>().limits.max = pressedPosition;
}

 
yo lo he intentado convertir....a este:
 

using UnityEngine;
using System.Collections;
public class Paddleh : MonoBehaviour {
 
public float restPosition = 0F;
public float pressedPosition = 45F;
public float flipperStrength = 10F;
public float flipperDamper = 1F;
 
void  Awake (){
   GetComponent<HingeJoint>().useSpring = true;
}
 
void  Update (){
   JointSpring spring = new JointSpring();
   spring.spring = flipperStrength;
   spring.damper = flipperDamper;
   if (Input.GetButton("Fire1"))
      spring.targetPosition = pressedPosition;
   else
      spring.targetPosition = restPosition;
   GetComponent<HingeJoint>().spring = spring;
   GetComponent<HingeJoint>().useLimits = true;
   GetComponent<HingeJoint>().limits.min = restPosition;
   GetComponent<HingeJoint>().limits.max = pressedPosition;
}
}

 
 
 
pero obtengo errores en las lineas:
 
 
 

GetComponent<HingeJoint>().limits.min = restPosition;
GetComponent<HingeJoint>().limits.max = pressedPosition;
Errores:
error CS1612: Cannot modify a value type return value of `UnityEngine.HingeJoint.limits'. Consider storing the value in a temporary variable
 
 error CS1612: Cannot modify a value type return value of `UnityEngine.HingeJoint.limits'. Consider storing the value in a temporary variable

 
Gracias de antemano.
 
 
#26
General (Antiguo) / Sonido no suena bien
Agosto 02, 2016, 05:04:44 PM
Buenas tardes,
 
tengo un pequeño dilema con un sonido.
 
me aseguro de que no suene nada mas , para que se active al llegar a 2 puntos,
 
Se activa el sonido pero no se para se reproduce una y otra vez...
 
Por mucho que miro no veo donde tengo el fallo....
 
A ver si ustedes me pueden ayudar, gracias.
 
 
 

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class puntos : MonoBehaviour
{
public static puntos instance;
public GameObject fireworks;
public GameObject tiempo;
public GameObject botonnivel1;
public AudioClip premio;
     AudioSource audio;
public void Awake()
{
   puntos.instance = this;
}
public float puntuacion = ;
public Text Puntos;
void Start()
{
   audio = GetComponent<AudioSource>();
   Puntos.text = "" + PlayerPrefs.GetFloat("Totales").ToString("f0");
 
}
   
  void Update ()
{
   if (puntuacion >= 2)
   {
   if (!audio.isPlaying)
   osito ();
 
   Puntos.text = " Puntos " + puntuacion.ToString ();
   }
   }
 
void osito()
{
      audio.clip = premio;
      audio.loop = false;
      audio.Play();
}
}

 
 
#27
General (Antiguo) / raycast va loco
Agosto 01, 2016, 02:05:50 AM
Hola buenas noches, queria preguntarles a ver si tienen alguna idea de porque el Raycast falla en este caso.
 
Bueno tengo un simple sistema de disparo el cual instancia un prefab y da fuerza a el RB etc.
 
Esto va de perlas .
 
El problema es cuando el raycast detecta el objecto al que colisiona en este caso "feria", l hace cuando le da la gana , aveces marca aveces no, al igual que se desvía solo , no siempre va recto y no lo entiendo, lo se por la marca de el agujero de la bala que instancia , si te mueves un poco es como si tardara en reaccionar o no se...alomejor se pega con todo lo que instancia y rebota..puede ser?
 
Lo curioso es que el objeto en si se destruye bien .
 
dejo el script , gracias de antemano.
 
 
 

using UnityEngine;
using System.Collections;
public class disparabolasandroid : MonoBehaviour {
public GameObject CannonBall;
public float shotForce = 1000;
AudioSource audio;
public GameObject explosion;
GameObject cannonBall;
public AudioClip sonidocanon;
private Animation anim;
public GameObject agujero;
public GameObject xispa;
 
void Start()
{
audio = GetComponent < AudioSource> ();
anim = GameObject.Find("pistola").GetComponent<Animation> ();
}
   
public void disparabola()
{
if (Input.GetMouseButtonDown())
explosion.SetActive (true);
cannonBall = GameObject.Instantiate(CannonBall as GameObject);
cannonBall.transform.position = transform.position;
RaycastHit hit;
Ray ray = new Ray (transform.position, transform.forward);
if (Physics.Raycast (ray, out hit,300f))
{
if (hit.transform.gameObject.tag == "feria")
{
puntos.instance.puntuacion = +1;
Debug.Log ("PUNTACO");
}
Instantiate (agujero,hit.point,Quaternion.FromToRotation(Vector3.up,hit.normal));
Instantiate (xispa,hit.point,Quaternion.FromToRotation(Vector3.up,hit.normal));
    }
Rigidbody rBody = cannonBall.GetComponent<Rigidbody> ();
rBody.AddForce (transform.forward * shotForce, ForceMode.Force);
audio.PlayOneShot(sonidocanon, 0.7F);
Instantiate (explosion,transform.position,transform.rotation);
cuentabolas.instance.bolas -= 1;
anim.Play ("fire1");
}

 
 
 
 
 
 
 
 
 
 
#28
General (Antiguo) / Cancelado
Julio 28, 2016, 04:19:11 PM
 
 
 
#29
General (Antiguo) / Duplicar enemigo
Julio 21, 2016, 07:37:07 PM
Buenas tardes,
 
Serian tan amables de darme una luz a este problema?.
 
Explico breve y claro.
 
Tengo una espada la cual esta con sus respectivos colliders y rigids, por otro lado tengo un enemigo el cual al recibir la castaña le baja la vida hasta que muere.
 
Esto funciona de maravilla hasta que duplico este enemigo para tener mas etc y no se porque no se les baja la vida si hay 2 pero si hay 1 si.
 
Daño de espada:
 

using UnityEngine;
using System.Collections;
public class dañoespada : MonoBehaviour {
public int damage = 10;
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "enemigo")
{
vidaenemigabichos.instance.vida -= damage;
//GetComponent<vidaenemigabichos>().vida -= damage;
Debug.Log ("le haces dañoooo");
 
}
}
}

 
vida del bixo:
 

using UnityEngine;
using System.Collections;
public class vidaenemigabichos : MonoBehaviour {
public static vidaenemigabichos instance;
public void Awake()
{
vidaenemigabichos.instance = this;
}
public int vida = 10;
private Animation anim;
public GameObject choke;
public AudioClip muerto;
 
void Update()
{
 if (vida <= ) {
  Debug.Log ("mueree");
  var clone = Instantiate(choke, transform.position, transform.rotation);
  Destroy (clone,6.0f);
 AudioSource.PlayClipAtPoint(muerto, transform.position);
//sangre.gameObject.SetActive(false);
Destroy(gameObject);
}   
}
   
}

 
Gracias.
 
 
 
 
 
 
#30
General (Antiguo) / Correr apretando dos teclas
Julio 14, 2016, 12:58:42 AM
Buenas noches,
 
Una pregunta por favor:
 
Tengo un simple input de teclas que mueven mi personaje con una animación con tecla asignada.
 
Quiero hacer que al apretar la tecla "flecha arriba" + control derecha , pues en vez de andar corra.
 
Para eso he creado dos variables distintas:
 
Velocidad y Correr con sus respectivas animaciones.
 
Pero al apretar simultaneamente o una tras de otra , no se ejecuta , le he puesto un debug,log pero tampoco aparece.
 

using UnityEngine;
using System.Collections;
public class moverplayer : MonoBehaviour
{
// En esta variable configuraremos la velocidad a la que se moverá el objeto
public float Velocidad = 1.0F;
public float Correr = 4.0F;
private Animation anim;
public float jumpHight = 0.5F;
public float jumptime = 0.300F;
public float smoothFactor = 5;
//public Quaternion rotation = Quaternion.Euler(new Vector3(0, 30, 0));
 
 
void Start()
{
   anim = GetComponent<Animation> ();
}
 
void Update ()
{
   
   // Movemos el objeto hacia adelante
   if (Input.GetKey (KeyCode.UpArrow)) {
      transform.Translate (Vector3.forward * Time.deltaTime * Velocidad);
      transform.forward = new Vector3 (0f, 0f, 1f);
      anim.Play ("walk00");
   }
   else if(Input.GetKey(KeyCode.DownArrow))
      
   {
      //atras
      transform.Translate(Vector3.back * Time.deltaTime * Velocidad,Space.World);
      transform.forward = new Vector3(-0f,0f,-1f);
      anim.Play ("walk00");
   }
   else if(Input.GetKey(KeyCode.RightArrow))
   {
      //derecha
      transform.Translate(Vector3.right * Time.deltaTime * Velocidad,Space.World);
      transform.forward = new Vector3(1f,0f,0f);
      anim.Play ("walk00");
   }
   else if(Input.GetKey(KeyCode.LeftArrow))
   {
      //izquierda
      transform.Translate(Vector3.left * Time.deltaTime * Velocidad,Space.World);
      transform.forward = new Vector3(-1f,0f,0f);
      anim.Play ("walk00");
   }
   else if(Input.GetKey(KeyCode.UpArrow) && Input.GetKey(KeyCode.RightControl))
   {
      
      Debug.Log ("correee");
      transform.Translate (Vector3.forward * Time.deltaTime * Correr);
      transform.forward = new Vector3 (0f, 0f, 1f);
      anim.Play ("run00");
   }
   else
   {
   anim.Play ("idle01");
   }
      
}
}

 
Agradeceria un consejo .
 
Gracias
 
 
 
 
 
 
 
 
#31
General (Antiguo) / Activar/Desactivar un Gameobject
Julio 08, 2016, 01:21:23 AM
Buenas noches,
 
Tengo una duda y después de mucho buscar recurro a ustedes,
 
Explico:
 
Tengo una escena(la principal), con un menú de niveles, bien , selecciono nivel 1 y la desactivo al cargar la siguiente escena.
 
dicho GameObject lleva un script de DontDestroyOnLoad (this.gameObject); añadido a el para que lo cargue en cada escena y pueda encontrarlo en las posteriores.
 
la desactivo de esta manera:
 

void Update ()
{
   if(nivel1)
   {
      Application.LoadLevel("leñador");
      selectniveles.SetActive(false);
   }

 
Hasta aquí de perlas, el juego empieza y bien.
 
El problema es cuando termino el nivel1 intento activar de nuevo el mencionado GameObject, pero no hay manera.
 
Tengo entendido que Unity no encuentra GO (GameObject) desactivados....
 
He probado:
 



   
      GameObject.Find("selectniveles").SetActive(true);
   

[/quote]
 
y todas las maneras activables, pero nada.
 
No encuentra el GO.....
 
Alguna idea de como activarlo?
 
 
 
Gracias de antemano.
#32
General (Antiguo) / Instanciando Enemigo
Julio 06, 2016, 06:23:13 PM
Buenas tardes,
 
Me esta llevando de cabeza lo que seguramente sera una tonteria pero no le veo el porqué...
 
Explico:
 
Tengo un cofre en la pantalla que al darle un par de yoyas se abre y crea un random de los prefabs que le añada.
 
Hasta aquí todo ok.
 
el problema viene cuando se instancian los prefabs en este caso enemigos,con sus scripts y todo en regla, aparecen en pantalla me siguen...pero no mueren!!.
 
El prefab que he creado lo añado manualmente a la escena y funciona....si lo añado desde los assets(lo arrastro a la lista de prefabs todo funciona menos el morir).
 
 
 
Aquí expongo los scripts:
 
Este instancia los prefabs:
 

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class vidaenemigacofre : MonoBehaviour {
public float vida = 2;
private AudioSource sonidocofreabre;
private bool cofreabre;
public GameObject cofrecerrado;
public GameObject cofreabierto;
public GameObject[]Items;
 
void Start()
{
   
   sonidocofreabre = GameObject.FindGameObjectWithTag ("sonidocofre").GetComponent<AudioSource> ();
   cofreabierto.SetActive(false);
 
}
void Update ()
{
   if (vida <= 0f) {
      if (!cofreabre)
         abriendo ();
      {
      }
   }
}
void abriendo ()
{
   cofreabre = true;
   sonidocofreabre.Play ();
   Debug.Log ("cofre se abre");
   Invoke ("abrierto", 2);
}
void abrierto ()
{
   cofreabierto.SetActive (true);
       cofrecerrado.SetActive (false);
   Instantiate(Items[Random.Range(,Items.Length)],transform.position,Quaternion.identity);
}
}

 
 
 
Este es la vida de la spider:
 

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class vidaenemigaspider : MonoBehaviour {
 
public float vida = 5;
public Animation anim;
public AudioClip audio1;
AudioSource audio;
private bool spidermuerto;
public siguejugador jugador;
void Start()
{
 audio = GetComponent<AudioSource> ();
}
void Update ()
{
   if (vida <= 0f) {
      if (!spidermuerto)
         spidermuere ();
      {
      }
   }
}
void spidermuere ()
{
   spidermuerto = true;
   jugador.enabled = false;
   audio.PlayOneShot (audio1, 0.3F);
   anim.Play ("die");
   Debug.Log ("spider muere");
}
}

 
 
 
y finalmente lo que le quita la vida a la spider:
 

using UnityEngine;
using System.Collections;
public class dañospider : MonoBehaviour {
public AudioClip muere;
//public vidaenemigaspider vida;
AudioSource audio;
 
void Start()
{
   audio = GetComponent<AudioSource> ();
    }
      
void OnTriggerEnter(Collider col)
{
   if (col.gameObject.tag == "spider") {
      Debug.Log ("muereee");
      audio.PlayOneShot (muere, 0.8F);
      GameObject.FindGameObjectWithTag ("spider").GetComponent<vidaenemigaspider>().vida -= 5;
   }
   }   
      
}

 
lo que me fijado es que al instanciar los prefabs los crea como (clones), pero el tag lo deja intacto lo cual no debería de afectarles.
 
Espero que tengan alguna idea que me esta volvindo loco!
 
 
 
Gracias de antemanoooo.
#33
General (Antiguo) / Tiempo de caida
Julio 01, 2016, 12:28:37 PM
Buenos dias , agradeceria una idea de como hacer que un árbol al caer caiga despacio y no de golpe como me esta pasando.
 
Estoy usando trasnform.Rotate con un float de speed para el ángulo y demás , también he probado con el drag de el rigidbody pero sin éxito.
 
Alguna idea por favor?
 
 
 

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class vidaenemiga : MonoBehaviour {
public static float vida = 5;
public Animation anim;
public float tiempocaida;
public AudioClip audio1;
AudioSource audio;
private bool arbolmuerto;
public GameObject tree;
public float speed =12f;
 
void Start()
{
audio = GetComponent<AudioSource> ();
tree = this.gameObject;
//GetComponent<Rigidbody>().isKinematic = true;
}
void Update ()
{
   if (vida <= 0f) {
      if (!arbolmuerto)
         arbolanima ();
      {
      }
   }
}
void arbolanima ()
{
   arbolmuerto = true;
   audio.PlayOneShot (audio1, 0.3F);
   //anim.play ("arbolanim");
   Debug.Log ("arbol caeee");
   //GetComponent<Rigidbody> ().drag = 50;
   transform.Rotate(Vector3.back,110*speed*Time.deltaTime);
   Invoke ("destruir",7);
}
       void destruir()
{
 
   Destroy(gameObject);
}
}
             
   
   

 
 
 
 
 
 
 
 
 
 
#34
General (Antiguo) / Sonido distorsiona
Junio 27, 2016, 01:19:21 AM
Muy buenas a todos, tengo un dilema muy raro....
 
Estoy intentando que suene un sonido normal y corriente cuando un árbol cae y hace su animación.
 
La cosa es que dicho sonido suena perfectamente por si solo, pero si le digo al script que me lo suene al caer el árbol suena distorsionado/con retardo/o como si estuviera en una cantera...
 
 
 
Aqui el script:
 

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class vidaenemiga : MonoBehaviour {
public static int vida = 5;
public Animation anim;
public float tiempocaida;
public AudioClip clip;
//   void Start()
//   {
//      AudioSource.PlayClipAtPoint (clip, Vector3.zero, 8.0f);
//   }
void Update()
{
   if (vida <= ) {
      vida = ;
      AudioSource.PlayClipAtPoint (clip, Vector3.zero, 1.0f);
      Debug.Log ("arbol caeee");
      anim.Play ("palmeracae");
}
}
   //Time.timeScale = 10f;
}

 
Veréis que en el Void Start lo tengo Togled es porque probé a ver si sonaba bien llamándolo desde el inicio antes que nada y si, el sonido va perfecto...Añado mas información , el script es simplemente un árbol que al darle con un axa se le quita vida nada mas y despues de morir(if vida <=0) hace sus cosillas  :), todas menos reproducir bien el sonido.
 
Y añado , si , tengo un Audio Source en el objeto.
 
Espero que tengáis una idea porque me esta llevando de cabeza el dichoso sonido...
 
Muchas gracias de antemano.
 
P.D he probado varios otros métodos Audio.Play, tranform position etc...y nada sigue sonando mal.).
#35
General (Antiguo) / Assets gratis de Unity
Marzo 13, 2016, 02:25:10 PM
Hola buenas tardes , tengo una pegunta que llevo dias dándole vueltas y no encuentro una respuesta clara.Estoy haciendo un pequeño proyecto para android y alomejor en un futuro lo pondré en la app store, la pregunta es:Los assets stores de unity (de la shop) los que pones free!! , se pueden usar para uso comercial sin problemas? o no todos se pueden ? Si alguin lo sabe por favor me gustaria saberlo para seguir con la idea o dejarlo para uso privado.Desde ya muchas gracias  
#36
Hola muy buenas, veréis , no se que demonios me he cargado de este código que me funcionaba bien...y ahora no veo por mucho que remiro donde tengo el error, la cosa es que la vida me baja cuando una bala me daña y llega a 0, pero no pasa nada osea se queda en 0 teoricamente deberia de hacer la animación bueno en este caso la explosión que le tengo asignada pero no pasa del 0, aver si alguien ve el error que seguro que es una tontería perore estoy rompiendo los cuernos y no lo veo!!, gracias de antemano!!! Gracias de antemano aquí el código: 
using UnityEngine;
using System.Collections;

    public class PlayerInfonaves : MonoBehaviour {
public GameObject laser1;
public GameObject laser2;
public GameObject monigote;
public GameObject healthBottle;
public GameObject player;
public AudioClip deathClip;
public AudioClip deathClip2;
public AudioSource sonido;
public AudioSource sonido2;
public float length;
public int Xmin = 400;
public int Xmax = 700;
public int Ymin = 300;
public int Ymax = 800;
public Transform spawnpoint;
public float timer2 = 40f;


int health = 100;
int damageCount = 0;
public float currentHealth;
bool playerFighting;
public GUIText healthbar;
float timer = 0.0f;
float healthTimer = 0.0f;
bool healthShouldRespawn = true;

public bool muerto = false;
public GameObject tuUI;

void Start () {
   currentHealth = health;
   tuUI.SetActive(false);
   }

void Update ()
{
timer2 -= Time.deltaTime;
//      if (timer2 < 0) {
//      timer2 = 100.0f;
//      currentHealth += 5;
//               }
   if (currentHealth > 100) {
   currentHealth = 100;
   }
   Cursor.visible = false;
   Debug.Log("player in combat? " + playerFighting);
   if(!playerFighting){
      Debug.Log("player is not fighting");
      if(currentHealth != 100){
         timer += Time.deltaTime;
         print ("timer: " + timer);
         if(timer > 0.5f){
            currentHealth += 0;
            timer = 0.0f;
      }
   }
   }
   else
   {
      if(currentHealth <= 0 && !muerto ){
         muerto = true;
         sonido.PlayOneShot(deathClip2);
         ///muerto2.play("muerto");
         GetComponent<PlayerControl>().enabled = false;
         laser1.SetActive(false);
         laser2.SetActive(false);
         monigote.SetActive(true);
         sonido2.mute = true;
         player.GetComponent<BloodSplat2>().enabled = true;

   
   



   
      }
   }
   healthbar.text = "Vida " + currentHealth + " / 100";
   
   if(healthShouldRespawn)
   {
      healthTimer += Time.deltaTime;
      
      if(healthTimer > 5.0f)
      {
         healthBottle.gameObject.SetActive(true);
         healthTimer = 1.0f;
      }
   }
   
   if(muerto){
      Cursor.visible = false;
      tuUI.SetActive(true);
      if(Input.GetKeyDown(KeyCode.Space)){
      Respawn();
      }
   }
   
}

public void ApplyDamage(int damage) {
   

   {
                       

      currentHealth -= damage;
      //check if health is lower than 0 when true it's set to 0 to avoid negative health.
      if (currentHealth < 0) {
         currentHealth = 0;
      }
      sonido2.PlayOneShot(deathClip);
      healthbar.text = "Health " + currentHealth + " / 100";
      damageCount =0;
   }
   
   print(currentHealth);
}

public void playerInCombat(bool combat){
   playerFighting = combat;
   playerFighting = true;
   }
      
public void Respawn(){
   tuUI.SetActive(false);
   muerto = false;
   player.gameObject.transform.position = spawnpoint.position;
   //transform.position = new Vector3(Random.Range(Xmin, Xmax),0, Random.Range(Ymin, Ymax));
   //transform.position = new Vector3(Random.Range(400.0f, 700.0f), 0, Random.Range(300.0f, 800.0f));
   GetComponent<PlayerControl>().enabled = true;
   player.GetComponent<BloodSplat2>().enabled = false;
   //Bocaarma.SetActive(true);
   laser1.SetActive(true);
   laser2.SetActive(true);
   monigote.SetActive(false);
   currentHealth = 100;
}

    void OnCollisionEnter (Collision collision) {
   Debug.Log("Hit by: " + collision.gameObject.name);


}

void OnTriggerEnter(Collider item){
   if(item.gameObject.tag == "PlayerHealthBottle")
   {
      if(currentHealth < 100)
      {
         currentHealth = currentHealth + 40;
         item.gameObject.SetActive(false);
         healthShouldRespawn = false;
         //Destroy(this.gameObject);
      }
   }
}
}
  
#37
General (Antiguo) / que estoy haciendo mal?, (SOLUCIONADO)
Diciembre 01, 2015, 06:51:34 PM
Hola muy buenas, tengo una duda y es que no se que estoy haciendo mal , me explico simple:creo un private gameobject para que no tenga que ponerlo cada vez y lo busque el script y así me evito ponerlo en cada enemigo.en este caso sangre.bien una vez definido y especificado (por gametag y nombre)le digo que lo active y desactive según necesidad.bien pues me tira error que no esta definido.Antes lo hacia con public y arrastraba el gameobject(sangreok, asi se llama) manualmente pero es un rollo para cada enemigo hacer eso , de echo realice lo mismo con el player y me funciona. Bien les dejo el script aver si me dan una luz 
using UnityEngine;
using System.Collections;
public class skellyattackgoul : MonoBehaviour {
public EnemyType myEnemyType;
private GameObject player;
private float distance;
public int damage =(10);
private GameObject sangre;
  //////  aqui el sangre
private PlayerInfo character;
private Animation myAnimation;
private float timer=0;
private bool shotdamage=true;

void Start () {
   player = GameObject.Find ("Jugador");
   sangre = GameObject.Find ("sangreok"); ////aqui el nombre de el gameobject con mismo tag.
   character = player.GetComponent<PlayerInfo>();
   myAnimation = gameObject.GetComponent<Animation>();
}

   // Update is called once per frame
   void Update () {
   if (!shotdamage) {
      timer += Time.deltaTime;
      if (timer >= 3) {
         shotdamage = true;
         timer = 0;
         sangre.SetActive(false);   ////desactivo
      }
   }
         

   distance = Vector3.Distance(player.transform.position,gameObject.transform.position);
      
      if (distance <= 3) {
      myAnimation.CrossFadeQueued("run", 0.3f, QueueMode.PlayNow);
      myAnimation.CrossFade("attack1");
      if (shotdamage) {
         shotdamage = false;
         sangre.SetActive(true); //// activo
         character.ApplyDamage (damage);
         //player.GetComponent<BloodSplat2>().enabled = true;
      }
   }

      
      else if (distance < 45 && distance > 3.0f) {
      myAnimation.CrossFadeQueued("attack1", 0.3f, QueueMode.PlayNow);
      myAnimation.CrossFade("run");
      gameObject.transform.LookAt(player.transform.position);
      transform.position = Vector3.MoveTowards(transform.position, player.transform.position, 0.2f);
      character.playerInCombat(true);
         
      }   
      else
      {
      //GetComponent<FollowPath>().enabled = true;
      myAnimation.CrossFadeQueued("run", 0.3f, QueueMode.PlayNow);
      myAnimation.CrossFade("idle");
      //player.GetComponent<BloodSplat2>().enabled = false;
      character.playerInCombat(true);
      }
   }
   
   
}
   
#38
General (Antiguo) / Necesito una idea...(RESUELTO)
Noviembre 24, 2015, 08:44:07 PM
Muy buenas a todos, necesito una idea,me intentare explicar lo mas claramente posible.Cree un sistema para cuando algun bixo me dañe, salga como una sangre en la pantalla con un Gui, bien hasta aqui ok , el scrip por si alguien le sirve es este:
sing UnityEngine;
using System.Collections;

public class BloodSplat : MonoBehaviour {
public Texture2D splat;
private float alpha = 1;
public float speed;
public bool test;
void OnGUI()
{
   if (alpha > 0.0)
   {
      Color color = Color.white;
      color.a = alpha;
      GUI.color = color;
      GUI.DrawTexture (new Rect(0, 0, Screen.width, Screen.height), splat);
      alpha -= speed*Time.deltaTime;
}}

void ApplyDamage ()
{
   alpha = 1f;
}

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

   {
      ApplyDamage();
   }

}
}
Esto funciona bien, el bicho me pega una yoya y se activa este script que esta en un empty GO. y lo llamo desde aqui (pongo el fragmento de codigo que lo llama que el resto es muy largo):
using UnityEngine;
using System.Collections;
public class skellyattackperro : MonoBehaviour {
public EnemyType myEnemyType;
private GameObject player;
public GameObject sangre;
private float distance;
public int damage =(10);
private PlayerInfo character;
private Animation myAnimation;
private float timer=0;
private bool shotdamage=true;


    void Start () {
   player = GameObject.Find ("Jugador");
   character = player.GetComponent<PlayerInfo>();
   myAnimation = gameObject.GetComponent<Animation>();
   }
   // Update is called once per frame
   void Update () {
   if (!shotdamage) {
      sangre.SetActive (true);
      timer += Time.deltaTime;
      if (timer >= 3) {
         shotdamage = true;
         timer = 0;
      }
   }
   else
   {
      sangre.SetActive (false);
   }
Bien hasta aquí todo ok!, pero el problema viene cuando aplico esto a varios enemigos diferentes, lo que les pasa es que uno de los tantos funciona pero los demás dejan de funcionar.En parte lo entiendo, si todos tienesn lo mismo y activan y desactivan el objeto en si, llega un momento que se vuelve loco.Probé también , a poner el script directamente a mi personaje principal y que el script de los enemigos lo llamara y lo activara y desactivara , pero el resultado es el mismo.Tambien se me ocurrió duplicar el scrip que activa la sangre y re nombrarlo y llamarlo desde cada bicho con un nombre diferente, ej sangre1, sangre2...etc pero nada caos total de nuevo lo unico que tenia eran 30 sangres renombradas y seguía sin funcionar. Alguna idea de como hacer que esto funcione? Gracias de antemano!!!     
#39
General (Antiguo) / Subir a un coche(Solucionado)
Noviembre 16, 2015, 08:07:27 PM
Muy buenas a todos, necesito una idea,me intentare explicar lo mas claramente posible.Tengo un coche, un script que lo conduce ya echo, una camara dentro de el coche y otra en el jugador si no esta en el coche.Bien todo esto va de fabula.El problema es, que cuando subo al coche(osea cambia de camara), desactivo la camara del jugador y activo la del volante,pero cuando me bajo de el coche...se cambia automaticamente a la camara de el jugador de apie..pero el jugador esta en el punto XXX y el coche esta en el quinto pino.Resumiendo alguna idea de como hacer que el coche(en moviemiento) y el jugador vayan a la par? osea que cundo me baje de el coche el jugador de apie este junto al coche no donde se cambio la camara...espero haberme explicado de no ser asi diganmelo por fafor. Gracias de antemano y un saludoAdjunto el script para que veais de que hablo. 
using UnityEngine;
using System.Collections;

public class coche : MonoBehaviour {


   //Variables
    public Camera camaracoche;
    public Camera camarajugador;
    public GameObject player;
   public Light LeftStop; // Left Stop Point Light
   public Light RightStop; // Reght Stop Point Light
   public Transform Car; // Your Car Model
   public Transform MyCamera; // Your Camera
   float movespeed = 0.0F;
   public float fuel = 1000.0F;
   int gas_pedal = 0;
   public int health = 100; // Not Used YET
   int rpm = 0;
   int gear = 1;
   bool isengine = false;
   public KeyCode addgas = KeyCode.W;
   public KeyCode removegas = KeyCode.S;
   public KeyCode clutchkey = KeyCode.Space;
   public KeyCode gearup = KeyCode.UpArrow;
   public KeyCode geardown = KeyCode.DownArrow;
   public KeyCode nogear = KeyCode.Alpha0;
   public KeyCode firstgear = KeyCode.Alpha1;
   public KeyCode seccondgear = KeyCode.Alpha2;
   public KeyCode thirdgear = KeyCode.Alpha3;
   public KeyCode fourthgear = KeyCode.Alpha4;
   public KeyCode fifthgear = KeyCode.Alpha5;
   public KeyCode reargear = KeyCode.Alpha9;
   public KeyCode startengine = KeyCode.E;
   public KeyCode ChangeCameraView = KeyCode.C;
   public KeyCode SteerLeft = KeyCode.A;
   public KeyCode SteerRight = KeyCode.D;
   public AudioClip EngineStart;
   public AudioClip EngineStop;
   public AudioClip IdleSound;
   public AudioClip GasPressed;
   public AudioClip BreakSound;
   
   void OnGUI()
   {
      GUI.Label(new Rect(5, 20, 100, 20), "RMP : " + rpm);
      GUI.Label(new Rect(5, 35, 100, 20), "Fuel : " + fuel);
      GUI.Label(new Rect(5, 50, 100, 20), "Gear : " + gear);
      GUI.Label(new Rect(5, 65, 100, 20), "Engine : " + isengine);
   }
   void Update()
   {
      
      if (fuel <= 0)
      {
         isengine = false;
         rpm = 0;
         
      }
      if (Input.GetKeyDown(startengine))
      {
         if (isengine == false)
         {
            if (fuel >= 1.50F)
            {
               isengine = true;
               fuel -= 1.5F;
               rpm = 1000;
               AudioSource.PlayClipAtPoint(EngineStart, Car.position);
               Debug.Log("Engine ON");
            player.GetComponent<CharacterController>().enabled = false;
            camaracoche.enabled = true;
            camarajugador.enabled = false;
         

            }
            else
            {
               Debug.Log("Not Enough Fuel!");
            }
         }
         else
         {
            isengine = false;
            rpm = 0;
            Debug.Log("Engine OFF");
            AudioSource.PlayClipAtPoint(EngineStop, Car.position);
             camaracoche.enabled = false;
             camarajugador.enabled = true;
             
         }
      }
      
      
      if (isengine == true)
      {
         
         //Fuel System
         if (rpm <= 1000)
         {
            fuel -= 0.025F;
         }
         else if (rpm > 1000 && rpm <= 2500)
         {
            fuel -= 0.5F;
         }
         else if (rpm > 2500 && rpm <= 4000)
         {
            fuel -= 0.8F;
         }
         else if (rpm > 4000 && rpm <= 5000)
         {
            fuel -= 1.0F;
         }
         else if (rpm > 5000)
         {
            fuel -= 1.9F;
         }
         //End Fuel
         //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         //Steer Syste
         if (Input.GetKey(SteerLeft))
         {
            if (movespeed <= 0)
            {
            }
            else
            {
               if (movespeed > 0F && movespeed <= 50F)
               {
                  Car.transform.Rotate(Vector3.down, 2F);
               }
               else if (movespeed > 50F && movespeed < 90F)
               {
                  Car.transform.Rotate(Vector3.down, 1.3F);
               }
               else if (movespeed > 90F)
               {
                  Car.transform.Rotate(Vector3.down, 0.9F);
               }
               
            }
         }
         if (Input.GetKey(SteerRight))
         {
            if (movespeed <= 0)
            {
            }
            else
            {
               if (movespeed > 0F && movespeed <= 50F)
               {
                  Car.transform.Rotate(Vector3.up, 2F);
               }
               else if (movespeed > 50F && movespeed < 90F)
               {
                  Car.transform.Rotate(Vector3.up, 1.3F);
               }
               else if (movespeed > 90F)
               {
                  Car.transform.Rotate(Vector3.up, 0.9F);
               }
               
            }
         }
         
         //End Steer
         //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         //Gas System
         if (Input.GetKey(addgas))
         {
            if (gas_pedal <= 100)
            {
               if (movespeed <= 0)
               {
                  if (gear == 1)
                  {
                     Car.transform.Translate(Vector3.forward * Time.deltaTime * movespeed);
                     gas_pedal += 1;
                     Debug.Log("GAS PRESSED " + movespeed + " " + gas_pedal + " " + fuel);
                     Debug.Log("GAS PRESSED " + movespeed + " " + gas_pedal + " " + gear + " " + rpm + " " + fuel);
                     AudioSource.PlayClipAtPoint(GasPressed, Car.position);
                     
                  }
                  else
                  {
                     isengine = false;
                     AudioSource.PlayClipAtPoint(EngineStop, Car.position);
                  }
               }
               else
               {
                  Car.transform.Translate(Vector3.forward * Time.deltaTime * movespeed);
                  gas_pedal += 1;
                  Debug.Log("GAS PRESSED " + movespeed + " " + gas_pedal + " " + fuel);
                  Debug.Log("GAS PRESSED " + movespeed + " " + gas_pedal + " " + gear + " " + rpm + " " + fuel);
                  AudioSource.PlayClipAtPoint(GasPressed, Car.position);
               }
            }
            else
            {
               Car.transform.Translate(Vector3.forward * Time.deltaTime * movespeed);
               Debug.Log("GAS PRESSED " + movespeed + " " + gas_pedal + " " + gear + " " + rpm + " " + fuel);
               AudioSource.PlayClipAtPoint(GasPressed, Car.position);
            }
         }
         else
         {
            if (gas_pedal > 0)
            {
               Car.transform.Translate(Vector3.forward * Time.deltaTime * movespeed);
               gas_pedal -= 1;
               Debug.Log("GAS PRESSED " + movespeed + " " + gas_pedal + " " + gear + " " + rpm + " " + fuel);
            }
         }
         if (Input.GetKeyDown(firstgear))
         {
            gear = 1;
         }
         else if (Input.GetKeyDown(seccondgear))
         {
            gear = 2;
         }
         else if (Input.GetKeyDown(thirdgear))
         {
            gear = 3;
         }
         else if (Input.GetKeyDown(fourthgear))
         {
            gear = 4;
         }
         else if (Input.GetKeyDown(fifthgear))
         {
            gear = 5;
         }
         else if (Input.GetKeyDown(nogear))
         {
            gear = 0;
         }
         if (Input.GetKey(removegas))
         {
            LeftStop.enabled = true;
            RightStop.enabled = true;
            if (gas_pedal > 0.0F)
            {
               gas_pedal -= 1;
               AudioSource.PlayClipAtPoint(BreakSound, Car.position);
               
               
               
            }
         }
         else
         {
            LeftStop.enabled = false;
            RightStop.enabled = false;
         }
         //End Gas
         //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         //RMP System
         if (gas_pedal >= 10 && gas_pedal <= 20)
         {
            switch (gear)
            {
            case 0:
               rpm = 3000;
               movespeed = 0.0F;
               break;
            case 1:
               rpm = 1800;
               movespeed = 8.0F;
               break;
            case 2:
               rpm = 1500;
               movespeed = 12.0F;
               break;
            case 3:
               rpm = 1200;
               movespeed = 5.0F;
               break;
            case 4:
               rpm = 1100;
               movespeed = 3.0F;
               break;
            case 5:
               rpm = 800;
               movespeed = 0.3F;
               break;
            case 9:
               rpm = 1700;
               movespeed = -9.0F;
               break;
            }
         }
         else if (gas_pedal < 10)
         {
            switch (gear)
            {
            case 0:
               rpm = 2000;
               movespeed = 0.0F;
               break;
            case 1:
               rpm = 1200;
               movespeed = 8.0F;
               break;
            case 2:
               rpm = 1000;
               movespeed = 12.0F;
               break;
            case 3:
               rpm = 800;
               movespeed = 5.0F;
               break;
            case 4:
               rpm = 400;
               movespeed = 3.0F;
               break;
            case 5:
               rpm = 200;
               movespeed = 0.3F;
               break;
            case 9:
               rpm = 1200;
               movespeed = -9.0F;
               break;
            }
         }
         else if (gas_pedal > 20 && gas_pedal <= 40)
         {
            switch (gear)
            {
            case 0:
               rpm = 5000;
               movespeed = 0.0F;
               break;
            case 1:
               rpm = 2800;
               movespeed = 14.0F;
               break;
            case 2:
               rpm = 2300;
               movespeed = 17.0F;
               break;
            case 3:
               rpm = 1800;
               movespeed = 24.0F;
               break;
            case 4:
               rpm = 1600;
               movespeed = 20.0F;
               break;
            case 5:
               rpm = 1200;
               movespeed = 15.0F;
               break;
            case 9:
               rpm = 2200;
               movespeed = -15.0F;
               break;
            }
         }
         else if (gas_pedal > 40 && gas_pedal <= 60)
         {
            switch (gear)
            {
            case 0:
               rpm = 7000;
               movespeed = 0.0F;
               break;
            case 1:
               rpm = 4500;
               movespeed = 18.0F;
               break;
            case 2:
               rpm = 2900;
               movespeed = 25.0F;
               break;
            case 3:
               rpm = 2400;
               movespeed = 35.0F;
               break;
            case 4:
               rpm = 2000;
               movespeed = 46.0F;
               break;
            case 5:
               rpm = 1700;
               movespeed = 56.0F;
               break;
            case 9:
               rpm = 4500;
               movespeed = -30.0F;
               break;
            }
         }
         else if (gas_pedal > 60 && gas_pedal <= 80)
         {
            switch (gear)
            {
            case 0:
               rpm = 9000;
               movespeed = 0.0F;
               break;
            case 1:
               rpm = 6500;
               movespeed = 24.0F;
               break;
            case 2:
               rpm = 4500;
               movespeed = 38.0F;
               break;
            case 3:
               rpm = 4000;
               movespeed = 75.0F;
               break;
            case 4:
               rpm = 3600;
               movespeed = 95.0F;
               break;
            case 5:
               rpm = 3000;
               movespeed = 120.0F;
               break;
            case 9:
               rpm = 4800;
               movespeed = -35.0F;
               break;
            }
         }
         else if (gas_pedal > 80 && gas_pedal <= 90)
         {
            switch (gear)
            {
            case 0:
               rpm = 14000;
               movespeed = 0.0F;
               break;
            case 1:
               rpm = 8700;
               movespeed = 32.0F;
               break;
            case 2:
               rpm = 7800;
               movespeed = 50.0F;
               break;
            case 3:
               rpm = 6700;
               movespeed = 106.0F;
               break;
            case 4:
               rpm = 4200;
               movespeed = 120.0F;
               break;
            case 5:
               rpm = 3800;
               movespeed = 140.0F;
               break;
            case 9:
               rpm = 5200;
               movespeed = -48.0F;
               break;
            }
         }
         else if (gas_pedal > 90 && gas_pedal <= 100)
         {
            switch (gear)
            {
            case 0:
               rpm = 17000;
               movespeed = 0.0F;
               break;
            case 1:
               rpm = 12700;
               movespeed = 42.0F;
               break;
            case 2:
               rpm = 8500;
               movespeed = 60.0F;
               break;
            case 3:
               rpm = 7400;
               movespeed = 126.0F;
               break;
            case 4:
               rpm = 5700;
               movespeed = 140.0F;
               break;
            case 5:
               rpm = 5200;
               movespeed = 180.0F;
               break;
            case 9:
               rpm = 8400;
               movespeed = -68.0F;
               break;
            }
         }
         //End RMP
         //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         //
         AudioSource.PlayClipAtPoint(IdleSound, Car.position);
      }
      else
      {
         if (Input.GetKey(SteerLeft))
         {
            if (movespeed <= 0)
            {
               
            }
            else
            {
               Car.transform.Rotate(Vector3.down, 0.4F);
               
            }
         }
         if (Input.GetKey(SteerRight))
         {
            if (movespeed <= 0)
            {
            }
            else
            {
               Car.transform.Rotate(Vector3.up, 0.4F);
               
            }
         }
         LeftStop.enabled = false;
         RightStop.enabled = false;
         if (movespeed > 0)
         {
            if (!isengine)
            {
               Car.transform.Translate(Vector3.forward * Time.deltaTime * movespeed);
               movespeed -= 1.0F;
               Debug.Log("GAS PRESSED " + movespeed + " " + gas_pedal + " " + gear + " " + rpm + " " + fuel);
            }
         }
      }
      
   }
   
}
 
   
#40
General (Antiguo) / Destruir clone(resuelto)
Noviembre 14, 2015, 07:16:38 PM
using UnityEngine;
using System.Collections;
public class Vidaenemiga3 : MonoBehaviour {
public float Vida = 400;
public Transform choke;
public AudioClip muerto;
void ApplyDammage ( int Dammage  ){
Vida -= Dammage;

if(Vida <= 0)
{
Muere();
}
}
void Muere (){
var clone = Instantiate(choke, transform.position, transform.rotation);
Destroy(clone,9.0f);
AudioSource.PlayClipAtPoint(muerto, transform.position);
Destroy(gameObject);
}   
}
Muy buenas a todos, llevo tiempo sin postear, porque voy aprendiendo despacito pero aprendiendo.Tengo ahora un pequeño dilema aver si alguien me puede dar luz.El script de arriba, intento que el "clone" se destruya a los 9 segundos despues de que se efectue.Pero me dice que no puedo destruir el Clone en si que destruia el objeto, pero no es lo que yo quiero solo quiero que se destruya el clone ya que es la animación que se hace al morir el enemigo y luego lo destruye todo. Alguna idea por favor?He probado con Destroy (this.gameObject,9.0f); pero sin resultados... Gracias