- Home /
Unity RayCast Selection
I've Denoted to simply trying to only select 1 unit.
var isSelected : Array[];
var mesh_on : boolean;
isSelected = false;
mesh_on = false;
function Update () {
var Units = 1 << 8;
var Ground = 1 << 9;
var ray = camera.ScreenPointToRay(Input.mousePosition);
var hit_unit: RaycastHit;
if(Input.GetMouseButton(0)){
var didHit: boolean = (Physics.Raycast(ray, hit_unit, Mathf.Infinity, Units));
if(didHit){
print(hit_unit.transform.name);
isSelected.Add(hit_unit);
}
else{
print("you hit nothing");
}
}
if(Input.GetKeyDown("w")){
hit_unit.transform.Translate(0, 0, 1);
}
var ray_ground = camera.ScreenPointToRay(Input.mousePosition);
var hit_ground: RaycastHit;
}
I don't understand why, but I'm getting Cannot convert boolean to Gameobject/Array :\ I'm sure there are other errors, but I'm going slightly insane now not finding away to Raycast and hit then add the hit object to a Selected group.
Comment
Answer by Anusha · Nov 02, 2012 at 03:20 AM
isSelected.Add(hit_unit.transform.gameobject);
the error says you are adding an boolean value instead of an game object, so change the above in your code.
Your answer
Follow this Question
Related Questions
unit selection issue 0 Answers
Math/Programming Question 4 Answers
Click and Drag RTS Mouse selecting script help. 1 Answer
RTS Game: Unit selection through Raycast 2 Answers