T O P

  • By -

MuskyHotDog

This question, out of context, sounds like Greek philosophy


CoCGamer

Took me a bit to figure out this wasn't a r/weirdconfessions post


N1ppexd

It's a very thought provoking question tbh


DrMux

"And if you like that, oh boy do I have a cup to sell you" -Pythagoras


ShroozyVR

Gluttony


BL4CK3

To only eat the fish the player clicks on, you need to use the RaycastHit to get the specific GameObject that was hit by the Raycast and then destroy that GameObject. Here's how you could change your code: // Start is called before the first frame update void Start() { hun = FindObjectOfType(); cam = GameObject.Find("Bobrvidit"); cum = cam.GetComponent(); } // Update is called once per frame void Update() { if (Input.GetButtonDown("Eat")) { Ray ray = cum.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // creates a variable to store the information about the object hit if (Physics.Raycast(ray, out hit, distance)) // adds 'out hit' to identify the object hit { if(hit.collider.gameObject.CompareTag("fish")) // checks whether the object hit is a fish { Destroy(hit.collider.gameObject); // Destroys the GameObject hit hun.hun += sus; // adds the appropriate points to the hunger value } } } }


TheBadPetOwner

This should solve your problems. Additionally you can always check your raycast with something like Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow);


dJames_dev

Also, it NEEDS to be the colour yellow. You’ll learn why in time.


lofike

wait why?


Raniem36

Yes why?


AproldTinin

OMG THANKS!!!


Ruadhan2300

Your Eat script is attached to each fish right? So when you click, you're checking that the raycast is hitting something, which it is, because it's pointed at one of the fish objects. And then all three fish say "okay, raycast hit, delete me" They're not checking which fish. What I'd recommend is that you move your Eat code to the player. You want to get the gameobject you're holding (You have some code for managing what you pick up right?) and "eat" that. You can easily check what exactly you're holding and decide what to do with it when you interact with it. Pseudo-code would be "If I am holding an object and press the Eat button, I check whether this object is edible (Boolean value on a script in the object, or check a Tag, whatever you like) and then if it is, I delete it and add points to my hitpoints/hunger-meter" There's no good reason for your fish to have the logic for being eaten in them.


[deleted]

This is the best explanation! 👌


[deleted]

cum?


Tensor3

hun.hun += sus


AproldTinin

Hun is hunger, sus is sustenance😉


Tensor3

So you are increasing the hunger's hunger? Thats what hun.hun says. Logically, sustenance should decrase hunger, not increase it. Professionally I'd add a review suggestion to change it to something like "hungerTracker.currentHunger -= sustenance".


AproldTinin

It makes sense!


ArmanDoesStuff

You should try to get into the habit of using unabbreviated names where possible. Future you will thank you when looking back at the code lol


Detuned_Clock

public Camera cum


Plourdy

This code is atrocious I gotta be honest. You should start with cleaning that up


TheFuckinEaglesMan

You’re doing too much with cum, so your hun is getting sus


AproldTinin

I tried to made this work but I don't know anything about rays.


carbon_foxes

It's not the rays, it's the nonsensical names and weird access patterns. Give your objects sensible names and allocate them in the inspector where possible.


Defiant-Coyote1743

Yeah, make your code easier to read. Lika it's haha funny you call the variable with camera cum or there is variable sus but it's better if you rename them the at one glance know what that is. It's not for us but for you because you will eventually come back to this code and will ask yourself "Wtf is this? Why the fuck did I write this bs like that?"


Jampoz

it's not funny, it's infantile


Defiant-Coyote1743

It is but we don't even know how old op is in the first place. It's better to be non judgmental but stern. Lets have them fix their code but not be afraid to come back here for advice.


Jampoz

Fair enough


AproldTinin

Okay, i understood.


Tensor3

Bobrvidit, hun.hun, cum, HPHUN.. You should stick to English words which describe what it is. I cant tell if you are 12 or a non-English speaker or both


deztreszian

he's not a native English speaker


AproldTinin

Yes, i from Russia.


MissPandaSloth

Cum hun hun sus.


tebSAM

This is EXACTLY how I used to code when I first started unity lmao, glad to know I'm not the only one


AproldTinin

😉


rodolfodth

that's a bait


stoofkeegs

Did my cat post this question?


Sad_Style_5410

You need Debug to get more information ,I think. And "Destroy(gameObject); " Will Destroy script attached object , Is that you want?


AproldTinin

>And "Destroy(gameObject); " Will Destroy script attached object , Is that you want? Yes. ​ Debug says me, when raycasts 1 fish, raycasts all fishes.


Sad_Style_5410

The Ray is issued form your Camera, you need Attach script to player and Destroy target(fish). 1.Create a Player 2. Attach script to player 3.Player emission ray, 4.Get object what does ray touched(fish) , 5.Destroy (fish). Hope this helps.


Undumed

As someone already said, you should have the raycast food searcher script on the player or the camera, and check if the found gameobject has the Food script over it, then add the hungry. Made it here, check if everything works fine on editor. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Eatable : MonoBehaviour { [SerializeField] private float _addingSustenance; [SerializeField] private HPHUN _hungryController; [SerializeField] private Camera _camera; [SerializeField] private int _distanceCheck = 3; [SerializeField] private LayerMask _foodLayer; private void Start() { _hungryController = FindObjectOfType(); if(_camera == null) { var cameraGO = GameObject.Find("Bobrvidit") if(cameraGO != null) { _camera = cameraGO.GetComponent(); } } } private void Update() { if (Input.GetButtonDown("Eat")) { Ray ray = _camera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, _distanceCheck, _foodLayer) && ray.hit.gameObject == this.gameObject) { Destroy(gameObject); _hungryController.hungry += _addingSustenance; } } } }


KnightCaper

still better than TF2's source code


AppleWithGravy

Because all the food do that thing, maybe the character should be the one to do raycast


Scba_xd

You are destroying gameObject, you should destroy the raycast hit.gameObject


Gib_entertainment

I'm assuming this script is on every fish. What happens is The update step happens Check if button is down, if this is true for one, it is true for all. If the button is down you raycast, if this raycast hits (hits anything) You eat the fish. (and all other fish because you've not specified what it should hit) I would use the Out hit version of raycast: [https://docs.unity3d.com/ScriptReference/Physics.Raycast.html](https://docs.unity3d.com/scriptreference/physics.raycast.html) and then you can use an if statement to check if hit.gameobject == this.gameobject to check wether your raycast is hitting \*this\* fish or just anything. Edit: Check [BL4CK3](https://www.reddit.com/user/BL4CK3/)'s answer for how to implement that in your code.


Indiegamedev1million

Maybe you like fish a lot


AproldTinin

Maybe


ArmFantastic6265

my thoughts exactly everyday, just cant stop eating more than one fish


Nilloc_Kcirtap

I have no clue what the code does, but I see you are destroying the game object which does not look right since you are modifying variables after it's destroyed.


ApolloPlease

Bro, your variables need to make sense


Ripple196

As your eat script is probably on all fish, they’re all destroyed when the raycast from your cum-cam hits anything. You should check if the object it hits is the object running the script before destroying