#Crystal text

1 messages · Page 1 of 1 (latest)

hallow heron
#

@robust yacht

robust yacht
#

good idea lol

#

thank you so much btw for all ur help, this has been a struggle for a good few hours lol

hallow heron
#

Umm is the list full of projectile?

robust yacht
#

no the list is instaniated prefabs

#

they just sit still when spawned it

hallow heron
#

And what does UpdateText look like?

robust yacht
#
    public void UpdateText()
    {
        s.AppendLine(crystal.crystalType[crystal.crystalType.Count - 1]);
        myText.text = s.ToString();
    }
hallow heron
robust yacht
#

ill give it another test and see

#

ah i see so i think it might be because i dont destroy the object instantly

#

imma turn of the 1 second delay and see

#

hmmmm

#

ok so what seems to happen is it will add 1 text, but then when i pick up another gem it will add loads of the pervious crystal name and then 1

#

So when i picked up the first one, it just had 1 speed

#

then the rest of the speeds appeared out of nowhere when i picked up the second

hallow heron
#

weird

#

You don’t have anything in the update right?

robust yacht
#

oh

#

in update i hate this

#
    void Update()
    {
        crystal.crystalType.ForEach(str => s.Append(str + " "));
    }
    public void UpdateText()
    {
        s.AppendLine(crystal.crystalType[crystal.crystalType.Count - 1]);
        myText.text = s.ToString();
    }
hallow heron
#

Ahh that’s why

robust yacht
#

ah

#

do i need that anymore

hallow heron
#

No

robust yacht
#

oh lolol

#

ok

#

sorry 😂

hallow heron
#

Hopefully that ends up being it

robust yacht
#

can i ask one final question

hallow heron
#

Sure

robust yacht
#

So now that I know it is storing these strings, how could i then translate these into bools for example so if i collect a jump crystal, i can add the buff

hallow heron
#

Oh so if you have the speed one, then it applies speed?

robust yacht
#

so like it increases the player by like 5 speed

hallow heron
# robust yacht yes for the player

It would be best to put it on the actual “speed crystal” but you can also use list.exists to see if a certain string exists in the list. It just has to search through the list every time to check https://www.geeksforgeeks.org/c-sharp-how-to-check-whether-a-list-contains-a-specified-element/

robust yacht
robust yacht
# hallow heron Wdym?

so in this example:

// C# Program to check whether the
// element is present in the List
// or not
using System;
using System.Collections;
using System.Collections.Generic;
 
class Geeks {
 
    // Main Method
    public static void Main(String[] args)
    {
 
        // Creating an List<T> of Integers
        List<int> firstlist = new List<int>();
 
        // Adding elements to List
        firstlist.Add(1);
        firstlist.Add(2);
        firstlist.Add(3);
        firstlist.Add(4);
        firstlist.Add(5);
        firstlist.Add(6);
        firstlist.Add(7);
 
        // Checking whether 4 is present
        // in List or not
        Console.Write(firstlist.Contains(4));
    }
}
hallow heron
#

It prints “True” because the list contains 4

robust yacht
#

ah so in my case, do i need to do the firstlist.add(1) and so on

#

or just put the list

#

because mine is a string

hallow heron
#

No, it’s just creating a new list of ints

#

As the example

robust yacht
#

ah

hallow heron
#

if(list.Contains(“Speed”))
{
AddSpeed();
}

#

or something

robust yacht
#

oh so i could literally just do a if statement

#

with list.contains

hallow heron
#

yeah since it returns a bool

robust yacht
#

beautiful, imma give that a go then

#

where does it return the bool?

hallow heron
#

for context:
bool someBool = (2 == 2); returns true
so someBool is equal to true

robust yacht
hallow heron
#

if(someBool)

robust yacht
#

so what is it if(list.contains("speed)) do

hallow heron
hallow heron
robust yacht
#

gotcha

hallow heron
#
void Start()
{
int value = 10;
int x = DivideHalf(value);
Console.Log(x);
}

int DivideHalf(int halving)
{
halving /= 2;
return halving;
}

//prints 5 to console
#

Example of a int return method

robust yacht
#

amazing it works

#

thank you so much for your help pumpkin, i really appreciate it, was a mega head scratcher for me

hallow heron
#

Glad to help 😅

robust yacht
#

@hallow heron sorry to ask again, this will be the final question, im trying to make it to where my player gets put to a position when a new scene loads, why cant i put my scene number in here?

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

public class ScenePlayerLoad : MonoBehaviour
{ 
        [SerializeField] private Transform player; 
        private Vector3 targetPosition; 

        private void OnEnable()
        {
            SceneManager.sceneLoaded += SceneLoaded; 
        }

        private void OnDisable()
        {
            SceneManager.sceneLoaded -= SceneLoaded;
        }

        private void SceneLoaded(Scene scene, LoadSceneMode mode)
        {
            if (scene == [0]) 
                player.position = targetPosition;
        }
}
hallow heron
robust yacht
#

"invalid expression"

#

I am trying to check if its the boss fight scene, if so teleport player to position

hallow heron
#

I don't think you need the [0]

robust yacht
#

ah so i must of read the documentation wrong

#

is it a string u put there?

hallow heron
robust yacht
#

ah, what is it i need to replace it with for it to work?

hallow heron
#

scene.buildIndex == 0 checks if scene is scene 0

robust yacht
#

Would i need to put the script on an object in the scene i want it to do it on?

hallow heron
#

int theLevel = SceneManager.GetActiveScene().buildIndex;

robust yacht
hallow heron
#

if(theLevel == 0)

GetActiveScene returns the currently loaded scene. build index is a property of a scene that tells you the build index

robust yacht
#

ah so i need to use getactivescene?

#

thank u for the documentation

#

So i can do
if(scenemanager.getactivescene() = 0

#

then move players position

#
public class ScenePlayerLoad : MonoBehaviour
{ 
        [SerializeField] private Transform player; 
        private Vector3 targetPosition;

    private void Update()
    {
        if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("Boss Fight"))
        {
            player.position = targetPosition;
        }
    }
}
#

I tried this

hallow heron
#

target position isn’t assigned unless you want it to be 0,0,0

#

@robust yacht

robust yacht
#

ah

#

So do i need to give it values in the start function

hallow heron
#

You could

robust yacht
#

okey

robust yacht
#

i gave the vector values in start but it didnt spawn my player there

#
    private void Start()
    {
        targetPosition = new Vector3(-91.59f, -1.20f, 0.0f);
hallow heron
#

I’ve never used the scene load += and -= before so I don’t really know what they do

robust yacht
#

lol

hallow heron
#

How are you changing scenes?

robust yacht
hallow heron
robust yacht
#

with a dontdestroy

hallow heron
hallow heron
robust yacht
#

since my other script already did that

#

and it didnt move me

hallow heron
#

try

      if (SceneManager.GetActiveScene().buildIndex == 0)
        {
            player.position = targetPosition;
        }

replace 0 with the build index of the boss fight

robust yacht
hallow heron
#

I just realized it will freeze the player

robust yacht
#

how come?

#

is it because theres a delay

hallow heron
#

if the scene is the bossfight, it constantly resets the player's position

robust yacht
#

well i dont even think it will work but i will try

#

considering our luck

#

huzza it worked

#

but yea it freezez me

hallow heron
robust yacht
#

theres only two scenes in terms of player movement and not ui

#

by default the player spawns in the correct position on the first level

#

but in the boss fight is the one im trying to fix

#

so it wont matter if its changed for the player for that specific part of the game

#

if thats what u mean

#

I mean i can make a bool and make the if statement a function on its own

#

actually that wouldnt work 😂

hallow heron
#
private Vector3 targetPosition
    void Awake()
    {
        SceneManager.sceneLoaded += OnSceneLoaded;
    }

    void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
       if(scene.buildIndex == 0)
        {
          player.position = targetPosition;
        }
    }

@robust yacht found something online that i modified

robust yacht
#

nevermind im special

hallow heron
#

wait the game is just 2 scenes?

#

@robust yacht

robust yacht
#

Yeah its for a game jam

hallow heron
#

oh nvm go back to what you had

robust yacht
#

nothing massive

hallow heron
#

that froze

robust yacht
#

how do we fix that then

#

well i have 3 scenes total

#

1 menu 2 levels

hallow heron
#
      if (SceneManager.GetActiveScene().buildIndex == 0)
        {
            player.position = targetPosition;
            this.enabled = false;
        }

either we destroy or disable the script

robust yacht
#

ah i see what ur doing

#

yea ill try that

#

Awesome it works, thanks a lot pumpkin, massive legend

hallow heron
#

good luck on the game jam!

robust yacht
#

@hallow heron if your still online i would love to know if it is possible to make it to where you can only have one buff showing in text, so if i pick up two speed crystals, the text still only has one speed

hallow heron