#i am too dumb lol

1 messages · Page 1 of 1 (latest)

fleet crane
#

i wanted to create a thread if this is ok

#

i dont want to bother other pp bc i am to dumb

coarse sphinx
#

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.

fleet crane
#

but yeah i really want to finish that

coarse sphinx
#

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.

fleet crane
#

do you need other scripts to understand it better?

coarse sphinx
#

Throw me the Item class

fleet crane
#

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

coarse sphinx
#

Ah, it's abstract so I assume you can have items other than weapons?

coarse sphinx
#

Give me the weapon class

fleet crane
#

huh

#

do you see it

#

or did it got deleted

coarse sphinx
#

throw it on pastebin

fleet crane
#

gocha

coarse sphinx
#
public class GunInfo : ItemInfo
{
    public float rateOfFire;
    public float damage;
}```
#

You have the info already here

fleet crane
#

Yup

#

and it doesnt work

#

like

#

🙂

#

doesnt work

#

XD

#

both still have the same firerate

#

but different damage

coarse sphinx
#

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.

fleet crane
#

can you send me what i have to type in the code

coarse sphinx
#

For example:

public class PlayerController
{
  float rateOfFire;
  Item weapon;

  rateOfFire = weapon.itemInfo.rateOfFire;
}
fleet crane
coarse sphinx
#

Well, you have to see where you're equiping the weapon and when you access the item object.

fleet crane
coarse sphinx
#

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.

fleet crane
#

so if i copy the example you send me into the player controller script it would work or not?

coarse sphinx
#

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.

fleet crane
coarse sphinx
#

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.

fleet crane
#

welp thats a bit complicated

coarse sphinx
#

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.

fleet crane
#

so in order to do what i want i have to access the player controller script?

coarse sphinx
#

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.

coarse sphinx
fleet crane
coarse sphinx
#
    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

fleet crane
#

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

coarse sphinx
#

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.

fleet crane
#

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

coarse sphinx
#

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.

fleet crane
coarse sphinx
#

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.

fleet crane
#

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

coarse sphinx
#

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

fleet crane
#

k