Making A 3D Maze Game in Unity - 8/10

Now we are going to make a collectables for the player. Our celectables are going to some default cubes. we will use the box collider of cube as trigger. the trigger will detect if the player object is colliding with it.just like the goal point. we will make a c# script to increase a public static variable of manager. Every time player game object hit a collectable gameobject, our collectables script will add +1 with the score.

Now make a new material for collectables and set it as you like. Here is my setting. 8.1.PNG

Now make a default cube. add the material to it. 8.2.PNG

rotate it from transfrom and here is my setting for transform of the collectables. 8.3.PNG

Check the isTrigger check box. 8.4.PNG

Make a new c# script and name it collectables. attach it with the collectables game object. copy paste this script and save it.

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

public class collectables : MonoBehaviour {
public int myScore;
// Use this for initialization
void Start () {
    
}

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

void OnTriggerEnter(Collider c){
    manager.score += myScore;
    Destroy (gameObject);

  }

}

select the collectables game object and will see this from the inspector tab.

8.5.PNG

the variable "increase" is to control the amount of score for every collectables. If you give a value of 20, score will be 20 for each collection. for now I just set 1.

Make it a prefab. Set it in the maze in multiple places.

8.6.PNG

AUTHOR

READ NEXT

Boostlog is an online community for developers
who want to share ideas and grow each other.

Delete an article

Deleted articles are gone forever. Are you sure?