I wish to assign a game object based on collision, i was essentially creating a empty object and assigning it to the variable then changing at run time but im assuming that you shouldnt need to do that.The basics of it is, you start off with no items inyour hand, you will have to pick one up . so when you collidee with an item you should then be able to pick it up and this assign the selectedTool to the gameObject in question
void OnCollisionStay(Collision Other)
{
startTime +=Time.deltaTime;
if(startTime >5.0f){
if(Other.collider.tag==("Pickable"))//change mayybe to pickable
{
if(Other.collider.gameObject.name =="Scalpal")
{
tools.selectedTool=0;
}
else if(Other.collider.gameObject.name=="scissors")
{
tools.selectedTool=1;
}
else{
tools.selectedTool=2;
}
bool isEquipped = CheckTools();//if true then something has been picked up
selectedTool = Other.collider.gameObject;
Debug.Log(selectedTool);
if(lastSelectedTool != null){//so if there was a tool which was last selected
lastSelectedTool.GetComponent<SelectableUtils>().unselect();//unselect it and give a new value
lastSelectedTool = selectedTool;
selectedTool.GetComponent<SelectableUtils>().select(isEquipped);
}
so at selected = other.colider.gameObject i get an error at runtime saying that the game object is not yet assigned when i actually collide with one of the items.
Are you sure that the item (in this case Other ) game object has a collider component?
– tzamoraYes, because Other.collider.gameObject.name returns the actual object when i put in in debug
– skyerzIm able to use
– skyerzif(Other.collider.gameObject.name =="Scalpal") { tools.selectedTool=0; selectedTool =GameObject.Find("Scapal");and it works fine, so there isnt anything wrong with the collider in that sense, there must be something that im doing wrong with regards to asigning game objects.You should show the exact error - they're usually pretty self-descriptive.
– Loiusthe error was UnassignedReferenceException: The variable selectedTool of 'SelectTool' has not been assigned. You probably need to assign the selectedTool variable of the SelectTool script in the inspector.
– skyerz