- Home /
How can i change this c# script from 3D to 2D ?
This C# script normally working in 3D game. But i want to change this code for 2D game. How can i do this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gameplay : MonoBehaviour {
public int force;
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.gameObject.CompareTag("cube"))
{
hit.collider.GetComponent<Rigidbody>().AddForce(Vector3.up * force);
}
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
counting score after destroying game object 1 Answer
so uhh.. how do you make sprites for the 4.6 UI? 2 Answers
Moving cube on x by 1 1 Answer
How can an UI Element know on which 3D Object it is pointing? 1 Answer
Distribute terrain in zones 3 Answers