Need help for a game I am trying to programm

Updated on September 26, 2017 in  [G] Say Hello!
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on September 26, 2017

Hello, I am a newbie at Unity and i thought could get some help here.

I have reached a point of my game where I can’t go further.

The problem is, I want to place an Ingame Button and when i press it, the Player changes materials. It works fine, now I want to place some obstacles in my level. The idea is, if the Player has the same material (for example blue color) as the obstacle, the player can go through it, otherwise if the Player hasn’t the same material (blue and the obstacle has a red material) the level resets.

Sadly i don’t know how to write it as a command. Maybe someone can help me here.

 

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

public class Obstacle_Blue : MonoBehaviour {

void OnTriggerEnter2D(Collider2D other)
{
//if tag “player” has same material as obstacle, then player can go through it, else scene resets
if (other.tag == “Player” && index = 1)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}

}

  • Liked by
Reply
0 on September 26, 2017

If you’re going for the color switch game then Brackeys did a video on it.

https://www.youtube.com/watch?v=gE7gc1sblUA

  • Liked by
Reply
Cancel