private void Update() { if (Input.GetButtonDown("Use")) { RaycastHit hit; Ray ray = Camera.mainCamera.ScreenPointToRay(new Vector2(_targetRect.x, _targetRect.y)); if (Physics.Raycast(ray, out hit, 8)) { // Did we targeted door? RRDoor door = hit.transform.gameObject.GetComponent <RRDoor>(); if (door) { if (door.Cube) { door.Cube.OpenDoor(door); } } else if (hit.collider.name == "Decal") { // Hit Decal - edit? } else { // Place decal GameObject decal = RRDecal.PlaceDecal((Texture)Resources.Load("Textures/IWasHere"), hit); decal.AddComponent(typeof(BoxCollider)); // Disable cube destroying hit.collider.FindParentWithTag("Cube").GetComponent <RRCube>().WorldBound = true; } } } }
public static GameObject PlaceDecal(Texture texture, RaycastHit hit, Vector2 scale) { GameObject gameObject = new GameObject("Decal"); gameObject.AddComponent(typeof(MeshRenderer)); MeshFilter meshFilter = (MeshFilter)gameObject.AddComponent(typeof(MeshFilter)); meshFilter.mesh = RRDecal.PlaneMesh; gameObject.transform.localScale = new Vector3(scale.x, scale.y, 1); gameObject.transform.position = hit.point; gameObject.transform.LookAt(hit.point + hit.normal); gameObject.transform.Translate(Vector3.forward * 0.0001f); gameObject.transform.eulerAngles = new Vector3(gameObject.transform.eulerAngles.x, gameObject.transform.eulerAngles.y, 0); gameObject.transform.parent = hit.transform; gameObject.renderer.material = new Material(Shader.Find("Transparent/Diffuse")); gameObject.renderer.material.mainTexture = texture; RRDecal.PositionMeshInBounds(gameObject, hit.collider.bounds); return(gameObject); }
public static GameObject PlaceDecal(Texture texture, RaycastHit hit) { return(RRDecal.PlaceDecal(texture, hit, new Vector2(1, 1))); }