Script doesn't work

I try this script to pick up object but it does nothing
The variable and some written are italian becouse i come from italy(sorry for my english) but the comand are right…
The result is that i see to the top of the screen the written “0 manufatti” and i can’t pick up object…
I put script on the first person, create a cube with tag “manufatto” and create a collider which have check the “is trigger” box. The cube isn’t been destroy when i touch it and i switch throught it…
Anyone can help me with simple words please?
Thanks for the help

Script:
var manufatto: int=0;
var vincita: int=7;

function OnTriggerEnter(other: Collider){
if(other.GameObject.tag==“manufatto”){
manufatto+=1;
Debug.log("Manufatto trovato! Sei a “+manufatto+” su "+vincita);
Destroy(other.GameObject);
}
}

function OnGUI(){
if(manufatto<vincita){
GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), “”+manufatto+" Manufatti");
}
else{
GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), “Trovati tutti i manufatti!!!”);
}
}

I would try converting it to spanish to see if it helps:

Guión:
artefacto var: int = 0;
var win: int = 7;

función OnTriggerEnter (otra: Collider) {
si (other.GameObject.tag == “artefacto”) {
artefacto + = 1;
Debug.log (“Artefacto encontró usted es un” + artículo + “a” + ganar);
Destruir (other.GameObject);
}
}

OnGUI función () {
si (artefacto <ganadora) {
GUI.Box (Rect ((screen.width / 2) -100, 10, 200, 35) “,” + + artefacto “Fabricación”);
}
else {
GUI.Box (Rect ((screen.width / 2) -100, 10, 200, 35), “encontraron todos los artefactos !!!”);
}
}

Guys please use code tags: Using code tags properly - Unity Engine - Unity Discussions

TTTTTa, I assume that’s humour.

1 Like

make sure the player has a collider attached:

also try setting the “manufatto” to inactive:

function OnTriggerEnter(other: Collider){
if(other.GameObject.tag=="manufatto"){
manufatto+=1;
Debug.log("Manufatto trovato! Sei a "+manufatto+" su "+vincita);
other.gameObject.SetActive(false);
Destroy(other.GameObject);
}
}

sorry Iraku i didn’t know the existence to code tag…
Anyway if i put a rigidbody and a collider on first person controller it doesn’t move… i have tryed the code above too but change nothing…

If you follow the rollaball tutorial, it will work.

here is the C# code. I do not know javascript but you should be able to convert it to JS.
no one will help if you continue to post code with italian words.

public class PlayerController : MonoBehaviour {
   
   void FixedUpdate()
   {

     float moveHorizontal = Input.GetAxis ("Horizontal");
     float moveVertical = Input.GetAxis ("Vertical");
     
     Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);     
     
     GetComponent<Rigidbody>().AddForce (movement*10.0f*Time.fixedDeltaTime);    

   }
[\CODE]

What does this code? it doesn’t do what i need why you post it? D:
anyway thanks for tutorial i hope to understand it…

I follow tutorial step to step and it is the same thing that i i do but doens’t work D: i control steps a lot and i m sure that i do all of them… what can be the problem? D:

You said when you put a rigid body on the player it doesn’t move, right? The above code makes the player move.

But i use a FirstPersonController i haven’t needed this code. The problem aren’t the player moving but the trigger event. In fact the function OnTriggerEnter don’t start and i have assigned the right tag. This is the problem

i have done a screen. there are the code and the object that i want to destroy. the script is on the FirstPersonController

your script isn’t attached to the cube.
click “Add Component” → scripts → raccogli.js

the script is on the FirstPerosnController. Anyway i try to add script to the cube too but it doesn’t work again