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!!!”);
}
}
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]
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:
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