#i am too dumb lol
1 messages · Page 1 of 1 (latest)
i wanted to create a thread if this is ok
i dont want to bother other pp bc i am to dumb
You should look up tutorials for structs and classes. C# language is built around these concepts so it's going to be hard to get far without this knowledge.
yeah i know but i REALLY want to finish that last thing and then next week my teacher will explain us about C sharp
but yeah i really want to finish that
So, you have different classes in your program. They make it easy to duplicate a bunch of code which saves a bunch of hassle. For instance, your Item class can make as many weapons possible with just that amount of code your wrote by just declaring Item in one of your scripts. Perhaps you've a machine gun or a pistol, they both can derive from the same class as they both can shoot and they both have a rate of fire.
I assume you've assigned some weapons on the inspector for this playercontroller script, and so you've an array of Items[] you delcared in it.
do you need other scripts to understand it better?
Throw me the Item class
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Item : MonoBehaviour
{
public ItemInfo itemInfo;
public GameObject itemGameObject;
public abstract void Use();
}
if you need more tell me
Ah, it's abstract so I assume you can have items other than weapons?
yup
Give me the weapon class
throw it on pastebin
gocha
the first one is gun .cs second guninfo.cs and the 3 is the gun itself
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
public class GunInfo : ItemInfo
{
public float rateOfFire;
public float damage;
}```
You have the info already here
Yup
and it doesnt work
like
🙂
doesnt work
XD
both still have the same firerate
but different damage
Ok, so when you equip your weapon, you need to check if it's a weapon which I assume you do. Then, you have to access the weapon data using a dot operator.
can you send me what i have to type in the code
For example:
public class PlayerController
{
float rateOfFire;
Item weapon;
rateOfFire = weapon.itemInfo.rateOfFire;
}
should i paste that in my code?
Well, you have to see where you're equiping the weapon and when you access the item object.
this happens in the player controller script right?
Yeah
So you see what's happening here, right? You delcare and instantiate an Item object. Then, to access the object you have to use these things called dot operators.
Inside of this Item object has all that data you want, and that's how you would access it.
so if i copy the example you send me into the player controller script it would work or not?
Classes create objects, they're just big containers of code and data.
Well, you access your items by an array. You have to apply the dot operator where you access the array and equip the item.
and this is the part where i know 100% that i REALLY have to learn C sharp i do not even know what an dot operator is
so i paste the code into that part where the weapon gets equipped
That's just an example how to access the data you want. Ok, so from that code, you can see I delcare an Item and named it weapon. Inside of this Item object variable, you have another container called itemInfo, so again to open that up you need to apply another dot operator. By doing that, you now have access to all the data inside of weapon.itemInfo, and so there's variables we can obtain from that. One of which is rateOfFire.
welp thats a bit complicated
This rateOfFire is independent of the playercontroller class, it exists on the item so that means if this variable changes, it would not reflect your rateOfFire variable on the playercontroller unless you access it again.
so in order to do what i want i have to access the player controller script?
It's more that you should be asking, how does my PlayerController class access this Item class.
And that's by delcaring an Item object into your playercontroller, and then using a dot operator on the Item to access the data.
float rateOfFire is local to your PlayerController script.
weapon.itemInfo.rateOfFire is a variable on the Item object that we named "weapon" here.
i still do not get what i have to do with that new information can you tell me like
in this script playercontroller you have to paste this right here and stuff
like i wont get it no matter how much you will explain it too me at that case it is my fault and after i finished that stupid shit i will learn c sharp properly
void EquipItem(int _index)
{
if (_index == previousItemIndex)
return;
itemIndex = _index;
items[itemIndex].itemGameObject.SetActive(true);
if (previousItemIndex != -1)
{
items[previousItemIndex].itemGameObject.SetActive(false);
}
previousItemIndex = itemIndex;
if (PV.IsMine)
{
Hashtable hash = new Hashtable();
hash.Add("itemIndex", itemIndex);
PhotonNetwork.LocalPlayer.SetCustomProperties(hash);
}
}```
You know how arrays work, right
well
no
i know 5%
like i kinda only wanted to do map design but it was very helpfull if i had a game to play the map on
There's probably a lot more you need to fix even with the information I'm giving you. It's probably a good idea to just keep going back over the tutorial since it seems like it should tell you how to do it.
the tutorial is done
i wanted to tweak things
is there a website where i can ask for code for this problem so i get that fixed fast
Well, you access your item here
items[itemIndex].itemGameObject.SetActive(true);```
So apply the dot operator once again and change the rate of fire on the player controller from this item.
From there, you'll have to debug it out.
This code is a quite a bunch from where you're at seeing that there's hashtables and stuff in this.
where do i have to put that in like in what script
rateoffire = items[itemIndex].itemInfo.rateOfFire;
or w/e it is locally called
like I said, there's probably some more stuff you need to debug, but that's something you need to learn since there's a lot more of this lol.
yeah i will leave it from here there is no point for me even trying that like the only thing i can do is to ask someone for the whole code or something but still thanks for helping
Honestly, spend like an hour going over a video on classes and you'll figure it out. I suggest understanding arrays first though.
Nothing is really difficult, it's just depends how much time you want to bang your ahead against these tutorials lol
k