I’m trying to create a Sims-like game focusing on interior design. I’ve been googling around and searching through the forums but can’t really get what I’m looking for. Hope you guys can point me in the right direction. I’ve attached a simple illustration of what I’m hoping to put together.
If I had a model of let’s say a chair, how do I project a semi transparent copy of that chair on the isometric plane below. Ideally i’m also hoping to show a colored shaft based on the object bounds connecting both the actual chair and the semi transparent copy.
I wrote a script similar to this when I was working on a tower defense project. I’ll just copy and paste what I wrote there and you can have fun with it lol (No licensing issues cuz it was just a practice project I was working on solo, not a real game that ever got released). Just attach it to any object in your hierarchy, attach some gameobjects to the lists and play around with it to see what it’s doing. Just play around with it and see what it’s doing and try to understand it. You will also need to adjust the physics so that you aren’t able to spawn objects on top of each other, I hadn’t gotten that far into it.
I never really finished the script nor refined it but if it’ll give you an idea on how to proceed with your game then it serves its purpose.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TowerPicker : MonoBehaviour
{
public List<GameObject> towers = new List<GameObject>();
public List<GameObject> ghostObjects = new List<GameObject>();
public int towerChoose;
GameObject _ghost;
int _elementPicker;
Vector3 _instantSpot;
bool _placing = false;
// This needs to be called from a UI.Button in the inspector. the int (sw) is basically the tower you want to spawn in the GameObject list. You can choose the parameter on the button.
public void Spawn(int sw)
{
_elementPicker = sw;
_placing = true;
ghost = ghostObjects[_elementPicker];
}
// This is spawning a ghost visual of the tower to show the player where they are placing it. You can play around with Y position to achieve the effect you are looking for in your game.
void SpawnPlacement()
{
Vector3 mousePosTest = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z);
Ray ray = Camera.main.ScreenPointToRay(mousePosTest);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if (!ghost)
{ Instantiate(ghost); }
_ghost.transform.position = hit.point;
_ghost.name = "GHOST TOWER";
_instantSpot = hit.point;
}
}
// Since it's a physics based method it should be placed in FixedUpdate
void FixedUpdate()
{
if (_placing)
{
SpawnPlacement();
}
}
// Escape button will cancel placement, otherwise left clicking will instantiate it and immediately turn off the placement.
void Update()
{
if (_placing)
{
if (Input.GetMouseButtonDown(0))
{
GameObject lala = Instantiate(towers[_elementPicker], _instantSpot, Quaternion.identity) as GameObject;
lala.name = lala.GetComponent<TowerScript>()._statData.name;
_placing = false;
}
if (Input.GetKeyDown(KeyCode.Escape))
{
_placing = false;
Destroy(ghost);
}
}
}
}
Million thanks for the help! First glance, looks like it’s exactly what I need. Any idea on the colored shaft connecting the actual object and the ghost object? Thanks again!
A colored cube would be easy - just use the object’s and the ghost object’s bounds to figure out the shape of the shaft. If you want a cylinder shape, use a cylinder that uses the bound’s x- and z-extents to find the radius (pick the larger, the smaller, depending on what looks good)
If you want a shaft that’s shaped like the outline of the object (ie. it looks like a shadow from a sun that’s straight above it), that’ll be much harder.