jueves, 11 de marzo de 2021

cambio de arma al pasar o tocar diversos objetos del player sobre ellos, como e echo el efecto de las minas,? como e echo el efecto de muescas al impactar las balas sobre los objetos ? suelo paredes muros etc....? ¿como e echo un cambio de arma del player, el protagonista del videojuego?

 

Pequeño resumen para el blog de lo aprendido por practicas en videojuego "warlike feats, "the documents" "

impacto de balas en los objetos, pequeñas muescas que se forman en las paredes muros o suelo.

efecto de minas al pasar el protagonista del juego el player por ellas y su efecto sobre el player

cambio de arma al pasar o tocar diversos objetos del player sobre ellos, como e echo el efecto de las minas,?

como e echo el efecto de muescas al impactar las balas sobre los objetos ? suelo paredes muros etc....?

¿como e echo un cambio de arma del player, el protagonista del videojuego?


Tema 1 minas.

Primero he echo un cubo con el nombre de tag “pomada” para que el player al pasar sobre el o tocarlo active una explosión y a la vez en su marcador de vidas pierda una vida, luego e duplicado sucesivamente este cubo y los hijos se los e puesto a un padre otro cubo, el primero de la idea, para no tener que ir trasteando de uno en uno que se hace tedioso e innecesario.

Cada mina tiene un script en C# llamado Activate Trigger


using System;
using UnityEngine;
using Object = UnityEngine.Object;

namespace UnityStandardAssets.Utility
{
public class ActivateTrigger : MonoBehaviour
{
// A multi-purpose script which causes an action to occur when
// a trigger collider is entered.
public enum Mode
{
Trigger = 0, // Just broadcast the action on to the target
Replace = 1, // replace target with source
Activate = 2, // Activate the target GameObject
Enable = 3, // Enable a component
Animate = 4, // Start animation on target
Deactivate = 5 // Decativate target GameObject
}

public Mode action = Mode.Activate; // The action to accomplish
public Object target; // The game object to affect. If none, the trigger work on this game object
public GameObject source;
public int triggerCount = 1;
public bool repeatTrigger = false;


private void DoActivateTrigger()
{
triggerCount--;

if (triggerCount == 0 || repeatTrigger)
{
Object currentTarget = target ?? gameObject;
Behaviour targetBehaviour = currentTarget as Behaviour;
GameObject targetGameObject = currentTarget as GameObject;
if (targetBehaviour != null)
{
targetGameObject = targetBehaviour.gameObject;
}

switch (action)
{
case Mode.Trigger:
if (targetGameObject != null)
{
targetGameObject.BroadcastMessage("DoActivateTrigger");
}
break;
case Mode.Replace:
if (source != null)
{
if (targetGameObject != null)
{
Instantiate(source, targetGameObject.transform.position,
targetGameObject.transform.rotation);
DestroyObject(targetGameObject);
}
}
break;
case Mode.Activate:
if (targetGameObject != null)
{
targetGameObject.SetActive(true);
}
break;
case Mode.Enable:
if (targetBehaviour != null)
{
targetBehaviour.enabled = true;
}
break;
case Mode.Animate:
if (targetGameObject != null)
{
targetGameObject.GetComponent<Animation>().Play();
}
break;
case Mode.Deactivate:
if (targetGameObject != null)
{
targetGameObject.SetActive(false);
}
break;
}
}
}


private void OnTriggerEnter(Collider other)
{
DoActivateTrigger();
}
}
}



que al tocarlas el player provoca el cambio de esta por un efecto de explosión, es muy importante que cada pieza de mina este nombrada con el tag de “pomada” por que el player tiene un script en C# llamado restavida



using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class restavida : MonoBehaviour {


// Create public variables for player speed, and for the Text UI game objects
public float speed;
public Text countText;
public Text winText;

// Create private references to the rigidbody component on the player, and the count of pick up objects picked up so far
private Rigidbody rb;
private int count;/// <summary>



// At the start of the game..
void Start ()
{

rb = GetComponent<Rigidbody>();

// Set the count to zero
//count = 0;////original
count = 10;
// Run the SetCountText function to update the UI (see below)
SetCountText ();

// Set the text property of our Win Text UI to an empty string, making the 'You Win' (game over message) blank
winText.text = "";
}


void OnTriggerEnter(Collider other)
{


if (other.gameObject.CompareTag ("pomada")){

other.gameObject.SetActive (false);///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Add one to the score variable 'count'
//count = count + 1;//////original
count = count - 1;

SetCountText ();
}
}

// Create a standalone function that can update the 'countText' UI and check if the required amount to win has been achieved
void SetCountText()
{


// countText.text = "VIDAS: " + count.ToString ();///original
countText.text = "VIDAS: " + count.ToString ();
// Check if our 'count' is equal to or exceeded 12
//if (count >= 10) ////original
if (count <= 1)

//if (count >= 99)
{
// Set the text value of our 'winText'
winText.text = "TE HAN MATADO";

//Destroy (gameObject, 1.2f);
Application.LoadLevel (1);


}
}
}







que tiene el tag nombra el tag de “pomada” para ir restando vidas al player asta hacer el cambio de gameobject del player el protagonista del videojuego desvaneciéndose en el suelo.



Mismo tag “pomada” que produce el sonido de muerte o desvanecimiento del player, en este script en C#


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SUENAALPERDERUNAVIDA : MonoBehaviour {

public AudioSource tickSource;

void Start () {

tickSource = GetComponent<AudioSource> ();



}

void Update () {
}



void OnTriggerEnter(Collider other) {
if (other.gameObject.CompareTag ("pomada")){


tickSource.Play ();



}}

}




Tema 2 muescas de balas en muros.

Aquí el proyectil que lanza el player esta nombrado con el tag "balaamericano" y el proyectil tiene este script en c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SANGRABALAAMERICANOELENEMIGO : MonoBehaviour {


public Rigidbody Sphere;
public float velocidad = 10f;
void disparador () {
Rigidbody SphereClon = (Rigidbody) Instantiate (Sphere, transform.position, transform.rotation);
SphereClon.velocity = transform.up * velocidad;


}

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


}

void OnTriggerEnter(Collider other) {

if (other.gameObject.CompareTag ("balaamericano")){

disparador ();///////////////////////////imbento yo


}}
}



A este script hay que arrastrarle en una casilla vaciá el gameobject que queremos se produzca cuando la bala toque otro objeto, yo e puesto unos cubos pequeñitos de los que sale humo….

Tema 3 cambio de armas…...continuara este me lo tengo que trabajar y estudiar mas porque en la versión web no me funciona al ser compilado aunque si funciona en la descargable para jugar desde este….continuara , paso el enlace de esta versión la 0,2,2 para que veáis lo aprendido practicado….