unity3d: 2. Procurement points, respawn

in #unity3d7 years ago

 

Hi, today I will show you how to capture points and make respawn to next level after captured all points, to work!


 I will introduce a simple method, on start, check that simple code below: 

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class Barrier: MonoBehaviour {

	public static int impediments = 4;
	public static int points =0;

	void OnTriggerEnter()
	{
	        points += 10;
		impediments -= 1;
		Debug.Log (points);
		Debug.Log (impediments);
		Destroy (gameObject);

		if (impediments == 0) 
                {
			SceneManager.LoadScene ("level1");
		}
	}
}

 First we have to add library on the top using UnityEngine.SceneManagement that we could use function from that library SceneManager.LoadScene („level1”); which it serves to loading the level. In quotes we have to enter name level, which we would like to move. I don’t have an idea so I called it level1.

Next we have got variable impediments, which to keep is number of impediments, variable impediments is static, so all object will be see how much objects is still in this level. Further is variable points, that variable representing how you think out number points.

Function OnTriggerEnter will execute when will to take place collision with player with object, using that function you must also check in object which serve for impediments function IsTrigger.

Next instructions means this same what points+=points + 10; so when to collision will succeed then quantity of points will be larger about 10 points. Next line it means that same what previous line only variavle is impediments. In next two lines are display values both variables in console. Next line are destroing which player to collided with. Farther is variable impediments will be eaqul 0 player goes to next map. If you want to move to next map, you have to move to bookmark file then Build Settings and drag and drop map to window Scenes In Build map which you want to move.

If you recognise it as useful, share it with others so that others can also use it and leave upvote and follow if you wait for next articles :)  

That’s all, maybe this isn’t perfect but on begining is good, see you later! 

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 62956.16
ETH 2588.54
USDT 1.00
SBD 2.74