Hey guys I am trying to deactivate a script called Interact from a code but I dont know how. Can someone show me how ?

using UnityEngine;
using System.Collections;

public class Loot : MonoBehaviour {

public int canOfBeans = 2;
public bool looted = false;
public GameObject Interact;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.E)){
canOfBeans += 1;
looted = true;

Taken();
}
}

void Taken ()
{
if (looted = true);
{
Interact = GameObject.Find("Stove").GetComponent<"Interact">.SetActive(false); 
} 

}
}

void Taken is a mess. Here’s how it should be:

void Taken()
{
    if (looted)
    {
        GameObject.Find("Stove").GetComponent<Interact>.SetActive(false); 
    }
}

I don’t know why you are trying to make a GameObject Interact and set it to an action SetActive(false). Those two things are completely different.

Yeah taken is a bit of a wreck…
Here’s your issues:

In an if statement you need to have two == signs when comparing something. On a bool statement you don’t need to do anything however which is why allen said just use looted.

This here is assuming that in your stove you want to be able to hit ‘e’ (note this is going to work anywhere when you hit ‘e’ regardless if you are aiming your mouse at it or not… so it’s probably not a good idea, you need to set up a raycast hit on what you are aiming at to make this work like I think you want it to - and you need to do the proper research to get to that point as it will open up a ton of doors for you). It’s a complex topic compared to the bool and syntax and you need to study it up a bit do some youtube vids and keep at it. It will pay off :slight_smile: don’t ever give up!

Keep in mind that game object find on stove is going to find the first one in the hierarchy. If you have multiple stoves - game object find will never find anything but the first one in the hierarchy (not very useful if you have more which is why you need the ray cast to pick the target up).

If you’re just adding 1 to canofbeans you can just do canofbeans++; Just an option - += works fine.