Unity 5 Voxel Engine Update – Photon Multiplayer

more stuff here. more stuff to do. stuff..n stuff..

1. Implemented multiplayer chat with Photon from exit games. I’m not looking to implement full multiplayer yet but perhaps a town or village where people can meet in between battles. It will be easier to learn Photon this way and also give me a chance to clean up the code a bit.

2. Added a Shakespearean random name generator.

3. Rewrote mesh distortion, vastly simplified version. Still needs some adjustment.

TODO: debug everything, re-write lighting code, add new mobs, npcs

Unity Drag & Drop Slots-Inventory

Many of you seasoned unity pros out there are probably face-palming as you look at how I’ve approached this, but this is the method that is working for me at this point. I’m sure it will be revised in the future.

The script below is attached to all of my quickslot UI images. I use an extra “phantom” slot (dragImage & dragText) to play the part of the slot that is being dragged. so the actual slots or slot items don’t move, the slot data is just passed behind the scenes. If you have any q’s  you can contact me dev@nuzly.com. otherwise, i hope this is useful in some way.

Also, check out this tutorial for a good run down on a variation of the code below. It’s the tutorial that clued me into this method, also check the unity forums for some useful unity 4.6 > 5 info. (which is where i got the UI raycasting stuff.)

using UnityEngine;
using System.Collections.Generic;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class DragHandler : MonoBehaviour,IBeginDragHandler,IDragHandler,IEndDragHandler {

    public GameObject dragObject;
    public Image dragImage;
    public Sprite emptyImage;
    public Text dragText;
    public int slot;
    SlotManager sm;
    Vector3 startPos;

	void Start () {

        dragObject = GameObject.Find("Slot_Drag");
        dragImage = GameObject.Find("Slot_Drag_Image").GetComponent();
        dragText = GameObject.Find("Slot_Drag_Counter").GetComponent();

        sm = GameObject.Find("InventoryUIManager").GetComponent();

    public void OnBeginDrag(PointerEventData eventData)
        dragImage.overrideSprite = sm.GetSlotSprite(slot);
        dragText.text = sm.GetSlotCountText(slot);
        startPos = dragObject.transform.position;

        sm.slotImages[slot].GetComponent().overrideSprite = emptyImage;
        sm.slotCounters[slot].GetComponent().text = "";


    public void OnDrag(PointerEventData eventData)
        Vector3 m = Input.mousePosition;
        dragObject.transform.position = new Vector3(m.x, m.y, dragObject.transform.position.z);

    public void OnEndDrag(PointerEventData eventData)
        dragObject.transform.position = startPos;

        dragImage.overrideSprite = emptyImage;
        dragText.text = "";

    void CheckDrop() 
        int dropSlot=-1;
        PointerEventData pointer = new PointerEventData(EventSystem.current);
        pointer.position = dragObject.transform.position;
        List raycastResults = new List();
        EventSystem.current.RaycastAll(pointer, raycastResults);

        if (raycastResults.Count > 2)
            string slotname = raycastResults[2].gameObject.name;

            if (slotname.IndexOf("Slot_01") > -1) { dropSlot = 1; }
            if (slotname.IndexOf("Slot_02") > -1) { dropSlot = 2; }
            if (slotname.IndexOf("Slot_03") > -1) { dropSlot = 3; }
            if (slotname.IndexOf("Slot_04") > -1) { dropSlot = 4; }
            if (slotname.IndexOf("Slot_05") > -1) { dropSlot = 5; }
            if (slotname.IndexOf("Slot_06") > -1) { dropSlot = 6; }
            if (slotname.IndexOf("Slot_07") > -1) { dropSlot = 7; }
            if (slotname.IndexOf("Slot_08") > -1) { dropSlot = 8; }
            if (slotname.IndexOf("Slot_09") > -1) { dropSlot = 9; }

        if (dropSlot != -1) 



Unity Custom Particle System – Test #1

Below are the functions I’m using to set scale and color. This is the first attempt. It seems to work OK but perhaps it can be improved on;

void SetColor()
new Color(Mathf.Lerp(startColor.r, endColor.r, lifeCounter / life), Mathf.Lerp(startColor.g, endColor.g, lifeCounter / life), Mathf.Lerp(startColor.b, endColor.b, lifeCounter / life), Mathf.Lerp(startColor.a, endColor.a, lifeCounter / life)));

void SetSize()
transform.localScale =
new Vector3(Mathf.Lerp(startSize.x, endSize.x, lifeCounter / life),
Mathf.Lerp(startSize.y, endSize.y, lifeCounter / life),
Mathf.Lerp(startSize.z, endSize.z, lifeCounter / life));

unity3d voxel game engine test #6 (Zombies Part.2)

I really need to keep a change log or something for this. Created a bunch of zombie textures and more models in blender. Added female and fat zombies with differing, xp, damage and move speeds. Recorded a bunch of sound effects and music. Fixed up some very very basic movement AI for mobs. They can now jump. Still no path finding. Added some more UI elements, power bar beside cross-hair, health bar for mobs, gold coins, exploding limbs, better decapitation and more. There is a smallish memory leak on loading new level. Otherwise happy so far.


unity3d voxel game engine test #5 (Zombies)

Added some more game elements to play with some ideas .. including headshot instakill on mobs with x2 xp. A lot more stuff to do yet. I’d made the zombie last year in blender so it’s the resident test mob for now. The zombie (boxy) model is compatible with minecraft skins so i should be able to use the existing skin editors to make a plethora of boxy type characters,npc etc though i may end up steering away from that style.