Making a 2D Game in unity part-8

After setting ui , our manager script will be ready to use. Now we will set the value of empty slots now. Drag and drop pause button object in the "pause button" slot of manager. Drag and drop pause panel object in the "pause panel" slot of manager. Drag and drop gameover panel object in the "pause panel" slot of manager. Drag and drop the score text we made in the "score" slot of manager.

1.PNG

make some image to set as collectables. First make the image in a image processing software and save individually each image.

Import the image of collectables in unity. Take them on hierachy and make a new script and name it "collectables​". this script will increase value from manager when the ball touch it. Attach the script with the collectable images and open the script on mono behaviour. copy paste this script to your "collectables​" script and save it.

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

public class collectables : MonoBehaviour {
public int adScore;
CircleCollider2D col;
// Use this for initialization
void Start () {
    col = GetComponent<CircleCollider2D> ();
}

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


void OnTriggerEnter2D(Collider2D col)
{ 

    manager.myScore += adScore;
    Destroy (gameObject);


}
}

attach a polygon collider to our collectable game objects and check the isTrigger section.

now this object will work as trigger.

You can set them in your tile prefab in different positions in the tile. make multiple tiles like that this will make random collectables format for player.

2.PNG

now this object will work as trigger.

You can set them in your tile prefab in different positions in the tile. make multiple tiles like that this will make random collectables format for player.

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?