Hello,
this is the script I am using:
var mouseOverColor = Color.blue;
private var originalColor : Color;
function Start () {
originalColor = renderer.sharedMaterial.color;
}
function OnMouseEnter () {
renderer.material.color = mouseOverColor;
}
function OnMouseExit () {
renderer.material.color = originalColor;
}
function OnMouseDown () {
var screenSpace = Camera.main.WorldToScreenPoint(transform.position);
var offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));
while (Input.GetMouseButton(0))
{
var curScreenSpace = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset;
transform.position = curPosition;
yield;
}
}
The script currently lets me grab an object if I look at it and hold the mouse button.
I am trying to edit it so that I can hold and object by looking at it and pressing E.
If the player presses E again, the he will drop it (like in source games).
I have tried everything I can imagine, but nothing worked. Can someone help me?
Thanks.