#Crystal text
1 messages · Page 1 of 1 (latest)
good idea lol
thank you so much btw for all ur help, this has been a struggle for a good few hours lol
Umm is the list full of projectile?
And what does UpdateText look like?
public void UpdateText()
{
s.AppendLine(crystal.crystalType[crystal.crystalType.Count - 1]);
myText.text = s.ToString();
}
So is it repeatedly adding projectile when you enter it or instant
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
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();
}
Did you still have the old code?
Ahh thatâs why
No
Hopefully that ends up being it
perfect, we got it working!
can i ask one final question
Sure
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
Oh so if you have the speed one, then it applies speed?
yes for the player
so like it increases the player by like 5 speed
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/
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
ah so for the first example, i would have to have seperate ones for each buff?
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));
}
}
It prints âTrueâ because the list contains 4
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
ah
yeah since it returns a bool
in the if statement
for context:
bool someBool = (2 == 2); returns true
so someBool is equal to true
but i mean like normally you have to declare like public bool name
if(someBool)
so what is it if(list.contains("speed)) do
^ this works
itâs a return type method. Some methods return ints or bools and stuff. That one searches through the entire list to see if anything == âSpeedâ and returns true if it finds anything
ah so if its true, it does whats inside of the if statement
gotcha
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
amazing it works
thank you so much for your help pumpkin, i really appreciate it, was a mega head scratcher for me
Glad to help đ
@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;
}
}
are you trying to find if the scene is the first index?
Well i just put the zero there to see if it would work and it had an error on that square bracket
"invalid expression"
I am trying to check if its the boss fight scene, if so teleport player to position
I don't think you need the [0]
its of type scene instead of int
ah, what is it i need to replace it with for it to work?
scene.buildIndex == 0 checks if scene is scene 0
ah ok
Would i need to put the script on an object in the scene i want it to do it on?
int theLevel = SceneManager.GetActiveScene().buildIndex;
what does this do?
if(theLevel == 0)
GetActiveScene returns the currently loaded scene. build index is a property of a scene that tells you the build index
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
You could
okey
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);
Iâve never used the scene load += and -= before so I donât really know what they do
well i decided to ditch them and do it when scene loads
lol
How are you changing scenes?
scenemanager.loadscene("string")
Ok so is there a player on every scene or are you moving it across
Moving it across
with a dontdestroy
hmm ok
You donât get a null reference exception right?
no
^ and this scene is also moving across?
well i dont think that specific code was working
since my other script already did that
and it didnt move me
try
if (SceneManager.GetActiveScene().buildIndex == 0)
{
player.position = targetPosition;
}
replace 0 with the build index of the boss fight
and should i put this on a script in update that has the dont destroy script on
I think so
I just realized it will freeze the player
if the scene is the bossfight, it constantly resets the player's position
well i dont even think it will work but i will try
considering our luck
huzza it worked
but yea it freezez me
is this the only scene where the position matters or are there other ones?
erm no
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 đ
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
nevermind im special
oooo
ok
Yeah its for a game jam
oh nvm go back to what you had
nothing massive
that froze
oh ok
how do we fix that then
well i have 3 scenes total
1 menu 2 levels
if (SceneManager.GetActiveScene().buildIndex == 0)
{
player.position = targetPosition;
this.enabled = false;
}
either we destroy or disable the script
ah i see what ur doing
yea ill try that
Awesome it works, thanks a lot pumpkin, massive legend
good luck on the game jam!
â€ïž
@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
Sorry, I was gone for awhile, hopefully itâs not too late. Youâll want to only AppendLine if the list doesnât contain the string.
void UpdateText()
{
if(list.Contains(âSpeedâ) == false)
{
AppendLine
}
else
{
// list already contains speed
}
}```