BuyMeACoffee

Buy Me A Coffee
Mostrando las entradas con la etiqueta Game Programming. Mostrar todas las entradas
Mostrando las entradas con la etiqueta Game Programming. Mostrar todas las entradas

jueves, 28 de abril de 2016

Uso de #Resources en #Unity



En los videojuegos muchas veces resulta necesario poder agregar objetos a la escena bajo ciertas condiciones, por ejemplo en el caso de videojuegos RPGs con magias, el elemento que tiene la animación y las partículas que representan la magia, debería ser creado cada vez que se utiliza la habilidad, las balas por ejemplo podrían igualmente ser creadas programáticamente a la escena cuando se necesitan y destruirse (eliminar de la escena) cuando ya no se necesitan.

En Unity la creación de objetos se puede hacer con Resources.
Vea el siguiente video para aprender como crear y destruir objetos de la escena utilizando Unity.




miércoles, 11 de marzo de 2015

Detective Kids videogame idea revealed

Detective Kids is a videogame currently in development, it has the objective to enhance kids deductive skills.

The game is about a kid who decides to explore beyond so decides to go out of the nerighborhood, as time passes our kid realizes is already nighttime and that is los, without any idea of the way home, nor any persons nearby that could be asked for help.

Our kid's mission is to find the way home, but there are challenges in the way.
The kid will get hungry and need to find food
The kid will get sad and need to find ways to recover an emotional balance
The kid will get tired and needs to find safe places to rest.
The kid will need to follow the clues in the way that will unblock others, eventually revealing the way home.
The kid will be affected by nature events such as rain, and snow, and needs to find ways to protect from these.

The mechanics will cause kids to use their max potential, enhancing their abilities.

The game is currently in the works, implementing some concepts of the core functionality.

Here is a video showing a concept for camera view, city layout, and attributes gauges


Stay tuned to this blog to know more of the progress.

lunes, 16 de febrero de 2015

Mini games

Explode The Bombs!


Find all bombs and make them explode, before there are too many.

First Stage



Second Stage



jueves, 1 de enero de 2015

Unity3D - Easily Handling Player's Objectives

A really easy way to handle player's objectives in Unity3D, is by taking advantage of these features:

  • Game Object hierarchy
  • Using public fields in scripts
  • Drag and Drop objects into public fields



With that said, this is what we can do:
  1. Create an empty game object
  2. Create a new child object per objective we want to represent
  3. Move each objective to the corresponding position(To make it easier you can click on the cube in the inspector once you have selected the objective, this will show the icon and name of the object in the Scene view)
  4. Attach a collider marked with trigger so that it does not block the player movement.
  5. Create a custom Objective script which will contain it's Name, Description, and other aspects required to handle it's behavior, including the action to perform when collider is reached. One of the important keys here is that each objective would have a "NextObjective" field, which is of the same type of the script(Objective). This helps reducing harcoded logic strings to go into the next objective.
  6. Create a Objectives script, which will contain a field for CurrentObjective and internally retrieves the list of all of the objectives in the hierarchy.
  7. Attach the Objectives script into the player's object, and drag your initial objective into the CurrentObjective field








These are the sample scripts:

Objective.cs:

using UnityEngine;
using System.Collections;
using System.Linq;
using System.Linq.Expressions;

public class Objective : MonoBehaviour
{

    public enum ObjectiveType
    {
        Reach = 0,
        Talk = 1,
        Defeat = 2,
    }

    public enum ObjectiveStatus
    {
        Pending = 0,
        Achieved = 1,
    }

    public enum ActionOnReach
    {
        MarkAsAchieved = 0,
        PlayCinematic = 1,
        PlayAnimation = 2,
        SetTrigger = 3,
    }

    public string Name;
    [Multiline(10)]
    public string Description;
    public ObjectiveType Kind;
    public ObjectiveStatus Status;
    public GameObject Target;
    public Objective NextObjective;
    public ActionOnReach[] ActionsOnReach;
    public Animator animator;
    public MovieTexture ClipToPlay;
    public string TriggerName;

    private void OnReach()
    {
        if (this.ActionsOnReach.Contains(ActionOnReach.MarkAsAchieved))
            this.Status = ObjectiveStatus.Achieved;
        if (this.ActionsOnReach.Contains(ActionOnReach.PlayCinematic))
            this.PlayCinematic();
        if (this.ActionsOnReach.Contains(ActionOnReach.PlayAnimation))
            this.PlayAnimation();
        if (this.ActionsOnReach.Contains(ActionOnReach.SetTrigger))
            this.NextObjective.Target.GetComponentInParent<Animator>().SetTrigger(this.TriggerName);

        ParentScript.CurrentObjective = this.NextObjective;

    }

    private void PlayAnimation()
    {
        Debug.Log("On PlayAnimation: Not implemented yet");
    }

    private void PlayCinematic()
    {
        Debug.Log("On PlayCinematic: Not implemented yet ");
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player" && this.ParentScript.CurrentObjective.name == this.name)
        {
            OnReach();
        }
    }

    public Objectives ParentScript { get; set; }
}


Objectives.cs

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Objectives : MonoBehaviour {

    public Objective CurrentObjective;
    private Objective[] PlayerObjectives;
    public Image CurrentObjectiveArrow;

    public Text CurrentObjectiveDescription; 

    void Start()
    {
        var objectiveParentGameObject = this.CurrentObjective.transform.parent.gameObject;
        if (objectiveParentGameObject != null)
        {
            this.PlayerObjectives = objectiveParentGameObject.GetComponentsInChildren<Objective>();
            if (this.PlayerObjectives != null)
            {
                Debug.Log("Succesfully found all player objectives");
                foreach (Objective singleObjective in PlayerObjectives)
                {
                    if (singleObjective != null)
                    {
                        singleObjective.ParentScript = this;
                    }
                }
            }
            else
                Debug.LogError("Unable to find objectives");
        }
    }

    void OnGUI()
    {
        this.CurrentObjectiveDescription.text = this.CurrentObjective.Description;
    }
}


This is just one way to do it, although it is not the only way, there are always other ways, some easier, some more complex, and complexity would be based on your game specific needs.