Im making a game that requires the player to interact with objects, and if lets say 1 wood collides with 1 other wood and the player presses a certain button, the wood turns into a wall, anyone know how i would accomplish this? For an example:
int wood = 2; // id of wood
if (wood collides){
if (input.getkeydown(keycode.f)){
wood = 4; // sets wood to another ID, i dont know if this is the best way to approach this, but it might work
}
}
Ok to be precise This is the script ive made so far, it doesnt “Work” but its getting somewhere.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CraftingSystem : MonoBehaviour { // Goes on every object that needs crafting.
public bool collided;
public string selfName;
public string collidedName;
public GameObject cube;
public bool InRange;
public bool LookAt;
// private float num = 1.0f;
// private Vector3 scale;
private void Update()
{
craftInstructions();
}
void Craft(int itemID, int outputID)
{
// Game IDs
int dirt = 1;
int stone = 2;
int wood = 3;
int log = 4;
int stick = 5;
int planks = 6;
if (itemID == 3 && outputID == 7)
{
Instantiate(cube, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z), Quaternion.identity);
Destroy(gameObject);
}
}
void craftInstructions() // Please, this will not work, It only crafts 2 things (Issue) regardless of what the materials are. Change this, also figure out how to connect to the prefabs folder without dragging stuff into it (Incase of unity update disconnecting all prefabs)
{
if (gameObject.transform.localScale.x < 0 && gameObject.transform.localScale.y < 0 && gameObject.transform.localScale.z < 0)
{
Destroy(gameObject);
}
if (collided)
{
if (Input.GetKeyDown(KeyCode.F) && InRange && LookAt)
{
Craft(3, 7);
}
}
}
void Items()
{
}
private void OnMouseOver()
{
LookAt = true;
}
private void OnMouseExit()
{
LookAt = false;
}
private void OnCollisionEnter(Collision collision)
{
collided = true;
}
private void OnCollisionStay(Collision collision)
{
collided = true;
}
private void OnCollisionExit(Collision collision)
{
collided = false;
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "p_reach")
{
InRange = true;
}
}
private void OnTriggerExit(Collider other)
{
if (other.tag == "p_reach")
{
InRange = false;
}
}
}