Hey, everyone. I’m having a problem with two scripts that I have. First of all i am complete noob :-P. the scripts that i am about to show are just some that i have got from tutorials from youtube and kinda combined them all into this one editing a few here in there to get it the way i like.
You will notice that one is JAVA and the other is C# which i assume might have something to do with the problem itself…
The first script here is the JAVA script, this basically is the movement of the camera, when the cursor hits the edge of the screen it moves the camera.
The second script is the Main one i use, it has everything from zoom in and out to the Selection Highlight for the units.
I really need both of these functions to work with my game, and if the first script was in C# i would try to merge it myself, but I honestly wouldn’t really know where to begin. If someone could help me Merge the two that would be perfect, or at least teach me how to make it to where they can coincide with each other without it messing up. as for now the first script doesn’t even work well.
Problem with the script: The java script will not move the camera if the main script (C#) is active, i did notice that it will move sometimes but not always. it will just scoot the screen over but it won’t go pass that.
Thanks for all of your help, i have been going around for about 10 hrs the past 2 days trying to get this figured out, but i can’t… thanks again for reading.
P.S All though i followed youtube videos to make these, i typed it all myself while following on so i could learn more, so the spacing of the code and the all out organization may not be the best…
var CamSpeed = 1.00;
var GUIsize = 25;
function Update () {
var recdown = Rect (0, 0, Screen.width, GUIsize);
var recup = Rect (0, Screen.height-GUIsize, Screen.width, GUIsize);
var recleft = Rect (0, 0, GUIsize, Screen.height);
var recright = Rect (Screen.width-GUIsize, 0, GUIsize, Screen.height);
if (recdown.Contains(Input.mousePosition))
transform.Translate(0, 0, -CamSpeed, Space.World);
if (recup.Contains(Input.mousePosition))
transform.Translate(0, 0, CamSpeed, Space.World);
if (recleft.Contains(Input.mousePosition))
transform.Translate(-CamSpeed, 0, 0, Space.World);
if (recright.Contains(Input.mousePosition))
transform.Translate(CamSpeed, 0, 0, Space.World);
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CameraOperator : MonoBehaviour
{
public Texture2D selectionHighlight = null;
public static Rect selection = new Rect(0, 0, 0, 0);
private Vector3 startClick = -Vector3.one;
private static Vector3 moveToDestination = Vector3.zero;
//Ground (walking Platform needs to be labeled "Floor" for following code)
private static List<string> passables = new List<string>() { "Floor" };
public float zoomMaxY = 0;
public float zoomMinY = 0;
public float zoomSpeed = 0.05f;
public float zoomTime = 0.25f;
public Vector3 zoomDestination = Vector3.zero;
private void Update()
{
CheckCamera();
Cleanup();
ZoomCamera ();
}
private void ZoomCamera()
{
float moveY = Input.GetAxis("Mouse ScrollWheel");
if (moveY != 0)
zoomDestination = transform.position + (transform.forward * moveY) * zoomSpeed;
if (zoomDestination != Vector3.zero zoomDestination.y < zoomMaxY zoomDestination.y > zoomMinY)
{
transform.position = Vector3.Lerp (transform.position, zoomDestination, zoomTime);
if (transform.position == zoomDestination)
zoomDestination = Vector3.zero;
}
if (transform.position.y > zoomMaxY)
transform.position = new Vector3 (transform.position.x, zoomMaxY, transform.position.z);
if (transform.position.y < zoomMinY)
transform.position = new Vector3 (transform.position.x, zoomMinY, transform.position.z);
}
private void CheckCamera()
{
if (Input.GetMouseButtonDown(0))
startClick = Input.mousePosition;
else if (Input.GetMouseButtonUp(0))
startClick = -Vector3.one;
if (Input.GetMouseButton(0))
{
selection = new Rect(startClick.x, InvertMouseY(startClick.y), Input.mousePosition.x - startClick.x, InvertMouseY(Input.mousePosition.y) - InvertMouseY(startClick.y));
if (selection.width < 0)
{
selection.x += selection.width;
selection.width = - selection.width;
}
if (selection.height < 0)
{
selection.y += selection.height;
selection.height = - selection.height;
}
}
}
private void OnGUI()
{
if (startClick != -Vector3.one)
{
GUI.color = new Color(1, 1, 1, 0.5f);
GUI.DrawTexture(selection, selectionHighlight);
}
}
public static float InvertMouseY (float y)
{
return Screen.height - y;
}
private void Cleanup()
{
if (!Input.GetMouseButtonUp(1))
moveToDestination = Vector3.zero;
}
public static Vector3 GetDestination()
{
if (moveToDestination == Vector3.zero)
{
RaycastHit hit;
Ray r = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(r,out hit))
{
while (!passables.Contains(hit.transform.gameObject.name))
{
if (!Physics.Raycast(hit.point + r.direction * 0.1f, r.direction, out hit))
break;
}
}
if (hit.transform != null)
moveToDestination = hit.point;
}
return moveToDestination;
}
}