I’m making a 2D platformer and I’m making a part where the player has a raycast go out of their head and I have the raycast code but it doesn’t work! I know it isn’t the code for it not being activated because a debug.log shows that it is and I have tried to debug this for hours and I can’t find the reason why it won’t work!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Talking : MonoBehaviour
{
[SerializeField]
private Text t;
public Text h;
public GameObject tb;
public float Health = 100;
public bool trialone;
public bool trialtwo;
public bool trialthree;
public int CanMove = 0;
public GameObject platform;
public float bhv;
public GameObject butterhead;
public GameObject humanhead;
public Movement m;
Scene currentScene;
string sceneName;
public bool whiteprivelege;
public bool floordanger;
public GameObject bread;
public GameObject knife;
public bool finale;
public Transform body;
RaycastHit2D Hit;
// Data miners, don't judge me this is a joke and don't leak this code or I will find your home adress :)
void Update()
{
currentScene = SceneManager.GetActiveScene();
sceneName = currentScene.name;
if (finale == true)
{
RaycastHit2D hit = Physics2D.Raycast(body.position, Vector2.up);
if (hit.collider.gameObject.CompareTag("God"))
{
Debug.Log("Pew Pew");
}
}
if (sceneName == "Butterland")
{
h.text = $"Health: {Health}";
}
if(bhv == 0)
{
butterhead.SetActive(false);
humanhead.SetActive(false);
}
if(bhv == 1)
{
humanhead.SetActive(false);
butterhead.SetActive(true);
}
if(bhv == 2)
{
butterhead.SetActive(false);
humanhead.SetActive(true);
}
if(CanMove == 0)
{
tb.SetActive(true);
}
if(CanMove == 1 && whiteprivelege == false)
{
tb.SetActive(false);
}
}
IEnumerator Start()
{
finale = false;
whiteprivelege = false;
currentScene = SceneManager.GetActiveScene();
sceneName = currentScene.name;
CanMove = 0;
Health = 100;
floordanger = false;
if (sceneName == "Butterland"){
bhv = 0;
tb.SetActive(false);
bool trialone = true;
Scene currentScene = SceneManager.GetActiveScene ();
string sceneName = currentScene.name;
Health = 100;
CanMove = 0;
bread.SetActive(false);
h.gameObject.SetActive(false);
yield return new WaitForSeconds(1.3f);
CanMove = 0;
bhv = 1;
t.text = "I am the god of butter you insolent fool!\nHow dare you consume my offspring!\nYou will be eaten if you don't undergo three trials!";
yield return new WaitForSeconds(4);
bhv = 2;
t.text = "Wait wait wait!\nDon't eat me please!\nWhat are the trials?";
yield return new WaitForSeconds(3);
bhv = 1;
t.text = "In the first trial You must avoid touching extremely hot butter falling from\nthe sky! If you fail you will die!";
yield return new WaitForSeconds(4);
t.text = "In the second trial it is of upmost importance that you avoid falling off\nthe slippery surface and not fall on the extremely hot floor!";
yield return new WaitForSeconds(4.7f);
t.text = "It is absolutely crucial that you understand that for the final trial\nyou will be placed on a slice\nof bread and must avoid butter knives trying to slice you!";
yield return new WaitForSeconds(3.3f);
bhv = 2;
t.text = "Is this gonna be hard?";
yield return new WaitForSeconds(1.5f);
bhv = 1;
t.text = "Of course this will prove to be extremely difficult! You have devoured\nmy offspring!";
yield return new WaitForSeconds(2);
bhv = 2;
t.text = "I'll try my best!";
yield return new WaitForSeconds(2.3f);
h.text = $"Health: {Health}";
h.gameObject.SetActive(true);
t.text = "Hey what's that number up there?";
yield return new WaitForSeconds(2.3f);
bhv = 1;
t.text = "I must inform you that the numerical value displayed on the top right corner\nrepresents your health bar.\nif this value reaches zero,\nit will result in your demise.";
yield return new WaitForSeconds(2.3f);
bhv = 2;
t.text = "I'll try to win the trials!";
yield return new WaitForSeconds(2.3f);
bhv = 1;
t.text = "Let The First Trial Begin!";
yield return new WaitForSeconds(1.5f);
bhv = 0;
CanMove = 1;
t.text = "";
One();
yield return new WaitForSeconds(45);
OneOver();
CanMove = 1;
bhv = 1;
tb.SetActive(true);
whiteprivelege = true;
t.text = "How could you of possibly survived that?";
yield return new WaitForSeconds(1.5f);
t.text = "I've had multiple people try that trial and they all failed!\nI'm suprised you are still alive! This trial will destroy you!";
yield return new WaitForSeconds(1);
t.text = "Get ready!";
yield return new WaitForSeconds(4);
whiteprivelege = false;
tb.SetActive(false);
bhv = 0;
Two();
yield return new WaitForSeconds(5);
floordanger = true;
yield return new WaitForSeconds(50);
TwoOver();
floordanger = false;
t.text = "I have never had someone able to survive this how did you manage to do that?";
yield return new WaitForSeconds(5f);
t.text = "Get ready!";
yield return new WaitForSeconds(5f);
bread.SetActive(true);
knife.SetActive(true);
Three();
yield return new WaitForSeconds(50f);
ThreeOver();
t.text = "This is outrageous I'm just going to kill you myself!";
CanMove = 0;
whiteprivelege = false;
bhv = 1;
yield return new WaitForSeconds(4);
bhv = 2;
t.text = "Wait don't kill me please! I'm sorry for eating butter!";
yield return new WaitForSeconds(5);
t.text = "Wait I remember now! I forgot to give grandpa his shotgun back!";
yield return new WaitForSeconds(6);
bhv = 1;
t.text = "Wait what? You have a shotgun? Don't shoot me!";
bhv = 2;
t.text = "Well bad day for you buckaroo you're gonna die!";
yield return new WaitForSeconds(4);
bhv = 0;
finale = true;
} }
void One()
{
trialone = true;
}
void OneOver()
{
trialone = false;
}
void Two()
{
trialtwo = true;
}
void TwoOver()
{
trialtwo = false;
}
void Three()
{
trialthree = true;
}
void ThreeOver()
{
trialthree = false;
}
}