Evening guys.
The script below is pretty much the collider and a method.
What I would like is the method to produce a random number each time a new prefab is cloned and what ever number is produced to go through the if statement. What is happening tho is that its producing a random number running through the if statement but also the else part. any ideas?
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
public class CollBeScript : MonoBehaviour
{
Collider2D coll;
System.Random rnd1 = new System.Random();
public int random1;
void start()
{
coll = GetComponent<Collider2D>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Player")
{
Debug.Log("collided");
Destroy (GameObject.Find("Beans" +"(Clone)"));
PerksorNot();
}
}
public void PerksorNot()
{
random1 = rnd1.Next(0,2);
if(random1 == 0)
{
Debug.Log("Score Doubled");
int newscore1 = PlayerScoreManager.Instance.Score * 2;
PlayerScoreManager.Instance.AddScore(newscore1);
}
if (random1 == 1)
{
Debug.Log("Score Halfed");
int newscore = PlayerScoreManager.Instance.Score /2;
PlayerScoreManager.Instance.RemoveScore(newscore);
}
else
{
Debug.Log("else");
}
}
}