Hey everyone
My class makes a school project for some kind of climate contest and I have to code a Game/App for that. We have a globe wich you can turn by swiping your finger ( around y and x axis). This is my code for that:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Swipe : MonoBehaviour
{
float rotSpeed = 40;
public GameObject Earth; //Parent object because I have the continents seperatly
void OnMouseDrag()
{
float rotX = Input.GetAxis("Mouse X")*rotSpeed*Mathf.Deg2Rad;
float rotY = Input.GetAxis("Mouse Y")*rotSpeed*Mathf.Deg2Rad;
Earth.transform.Rotate(Vector3.up, -rotX, Space.World);
Earth.transform.Rotate(Vector3.right, rotY, Space.World);
}
}
This works fine, but now you I have to code that you can click on a continent. I think my class wants to fill in the CO² usage of this continent. For that, I have this code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tap : MonoBehaviour
{
public GameObject Text;
int counter = 0;
void OnMouseOver() {
if(Input.GetMouseButtonDown(0)) {
counter++;
if (counter % 2 == 1){
Text.SetActive(true);
} else {
Text.SetActive(false)
}
}
}
}
I will work on cool animations later, but now I will come to the point: The continent will also get clicked, if you want to swipe and start on the continent (I new that when I wrote the code but I didn`t have a better option). I know there are some other questions about it but I want to have a solution especially for that.
Thank you very much for helping me!
Here is a photo for you: