我已经为Unity 2D寻找了一个对象拖动脚本.我在互联网上找到了一个很好的方法,但它似乎只是在Unity 3D中工作.这对我来说并不好,因为我正在制作一个2D游戏并且它不会以这种方式与"墙壁"发生碰撞.
我曾尝试将其重写为2D,但我已经使用Vectors崩溃了.
如果你能帮我把它重写成2D,我会很高兴的.
以下是3D中的代码:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(BoxCollider))]
public class Drag : MonoBehaviour {
private Vector3 screenPoint;
private Vector3 offset;
void OnMouseDown() {
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
}
Run Code Online (Sandbox Code Playgroud) 对不起,我是初学程序员,现在我只学习Android Java特定语言.我有一本书,我想学习,但是当我创建一个新项目时,我没有原始文件夹.我该怎么做?或者之前我删除了它?我不知道,因为我只是试图发现Eclipse IDE,我犯了一些错误.:)
谢谢!
我有一个游戏,我在Unity中以480x320的分辨率(我在构建设置中设置了它).但我想为每个Android设备发布我的游戏,每个分辨率.我怎么能这样做,告诉Unity将我的游戏扩展到设备的分辨率?有可能吗?
提前致谢!
我是从Libgdx引擎到Unity的,我是初学程序员.我尝试在Unity中为Android和iOS设备制作游戏,但我对纵横比/分辨率缩放有问题.在Libgdx中,如果你开发了一些东西,你会给出一个"默认"分辨率,并且所有内容都会缩放到设备的屏幕上,无论它的分辨率是大还是小,都不会从屏幕上切掉任何东西.另一方面,在Unity中,如果我制作游戏,它会将屏幕裁剪为所选的宽高比,如果您希望在所有可用设备上获得相同的体验,这不是最好的.我在互联网上搜索了很长时间,但我找不到任何对我有用的东西.
结论:我想知道Unity(C#)是否有一些代码可以使我的游戏在所有具有不同宽高比的设备上看起来都一样?我正在使用Unity 2D进行开发.如果有人可以编码并希望分享它,我会非常高兴,因为如果在所有设备上看起来都不一样,那就非常糟糕.我还没有onGUI的问题,因为我没有做过任何菜单或其它东西,只是游戏,但是在设备上背景不一样并且角色没有打开是不好的屏幕的相同部分.
android aspect-ratio screen-resolution unity-game-engine ios
这是代码:
class Fibonacci {
static final int MIN_INDEX = 1;
public static void main (String[] args){
int high = 1;
int low = 1;
String jel;
System.out.println("9: " + high);
for (int i = 8; i >= MIN_INDEX; i--){
if (high % 2 == 0)
jel = " *";
else
jel = " ";
System.out.println(i + ": " + high + jel);
high = low + high;
low = high - low;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想制作这个程序,向后写输出数字.所以我不仅希望从最后一个到第一个的'i'步骤,而且也想要数字.
在这个例子中,输出是:1,1,2,3,5,8,例如......但是我想在序列中显示它:例如......,8,5,3,2,1 ,1.
我试图改变高低,但我不能让这个程序强制"向后"运行.
我想在C中制作一个二维数组.
例如,我创建一个名为place的int类型变量,如下所示:
int *place;
Run Code Online (Sandbox Code Playgroud)
我有一个游戏,它有像行和列这样的变量.我希望我的place变量是一个二维数组,动态分配它的行和列(对于数组的最大大小),在"普通"声明中看起来像这样:
place[rows][columns];
Run Code Online (Sandbox Code Playgroud)
但我不知道如何用动态分配来做到这一点.
对于一维数组我会这样做:
place = (int*) malloc (levels * sizeof(int));
Run Code Online (Sandbox Code Playgroud)
但我不知道如何用2D数组做到这一点.
编辑:
我如何为char而不是int重写这个?
我试图用chars覆盖整数,但它不起作用.
我通过互联网查看了很多android教程.在这些教程中,他们this在各处使用上下文.我知道thisJava中的关键字意味着什么,但我不能this在Android编程中使用关键字.例如,在AlertDialog.Builderdeveloper.android.com网站上,在Context的参数中只有一个引用,但我不知道这this意味着什么.
我正在考虑将Leadbolt(或Tapjoy)整合到我的Libgdx游戏中.我想根据点击的表格建立商店.更多点击 - 来自商店的更多东西给用户.我找到了Leadbolt和Tapjoy.这些广告提供商正在为这些内容提供直接帮助.我看一下Leadbolt集成指南.我有一个问题.它需要我将一个上下文传递给AdController.我不知道是否有可能以任何方式传递AdController的上下文,所以我想问你一下,如果可以,我该怎么办?(我还没有在Libgdx中尝试过,但是当superjumper示例也存在问题时,当我想传递某个上下文时,我认为因为Libgdx应用程序没有扩展Activity,所以它也会有问题. )
以下是Leadbolt的示例代码:
AdController myControllerForm = new AdController(this, "MY_LB_ID", new AdListener() {
public void onAdProgress() {}
public void onAdLoaded() {
myControllerForm.hideAd();
}
public void onAdFailed() {
launchMain();
}
public void onAdCompleted() {
myControllerForm.hideAd();
launchMain();
}
public void onAdClosed() {
launchMain();
}
public void onAdClicked() {}
public void onAdAlreadyCompleted() {
launchMain();
}
public void onAdHidden() {
launchMain();
}
});
myControllerForm.setAsynchTask(true);
myControllerForm.loadAd();
}
public void launchMain()
{
finish();
startActivity(new Intent(Splash.this, MainApp.class));
}
}
Run Code Online (Sandbox Code Playgroud)
该类扩展了Activity,这个方法在本例中的onCreate()方法中.
如果你已将Leadbolt或Tapjoy集成到你的Libgdx游戏中,那么请你给我一个关于你是怎么做的代码的?
提前致谢!
我该怎么办?我做了一个全新的项目,但错误在这里:R无法解决.错误setContentView(R.layout.main);在行中.
我是一个新的Unity用户,我只是在Unity 2D游戏示例中尝试一些脚本.现在我想建立一个游戏门户网站,我已经在互联网上找到了一个脚本,但它是用UnityScript编写的,但我的游戏是用C#编写的,所以我想将它写入C#.我有一个getComponent方法的问题,因为我得到错误,如果我使用它,因为它在JS中.我想问你应该写什么代替GetComponent,或者我应该怎么写它.
这是JS脚本:
var target : GameObject;
var adjust : float;
var jump : boolean;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
function OnTriggerEnter(other : Collider) {
if (!jump) {
if (other.tag == "Player") {
target.GetComponent(Teleport).jump = true;
other.gameObject.transform.position = Vector2 (target.position.x, target.position.y);
}
}
}
function OnTriggerExit(other : Collider) {
if (other.tag == "Player") {
jump = false;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在下一个代码中得到了这些错误:
public float …Run Code Online (Sandbox Code Playgroud) 我想在Eclipse中用Java创建一个程序,告诉我,如果我可以创建三角形.这是我的代码:
import java.io.IOException;
public class haromszog {
public static void main(String[] args) throws IOException {
int a;
int b;
int c;
System.out.print("Please insert the 'a' side of the triangle:");
a = System.in.read();
System.out.print("Please insert the 'b' side of the triangle:");
b = System.in.read();
System.out.print("Please insert the 'c' side of the triangle:");
c = System.in.read();
if ((a+b)>c)
{
if ((a+c)>b)
{
if ((b+c)>a)
{System.out.print("You can make this triangle");
}
else
System.out.print("You can't make this triangle");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Eclipse可以运行它,但它写道:
请插入三角形的'a'侧:(例如我写:):5 …
我有一个主类,看起来像这样:
class Main {
public static void main (String[] args) {
Mobil one = new Mobil ("xxxxxx", "yyyyyy", 00000001, true);
Mobil two = new Mobil ("yyyyyy", "xxxxxx", 10245624, false);
one.touchcontrol();
two.touchcontrol();
}
}
Run Code Online (Sandbox Code Playgroud)
我有这个美孚课程:
class Mobil {
String type;
String manufactureat;
int modellnumber;
boolean touchtype;
public Mobil (String manufacturer, String inittype, int number, boolean touch) {
manufacturer = manufactureat;
inittype = type;
number = modellnumber;
touch = touchtype;
}
public void touchcontrol() {
if (touchtype == false)
{
System.out.println("This model, …Run Code Online (Sandbox Code Playgroud) 这里是代码:public class beautiful extends Activity {ImageView radar =(ImageView)findViewById(R.id.radar);
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.beautiful);
Button search = (Button) findViewById(R.id.magnifier);
ImageView text = (ImageView) findViewById(R.id.text);
MediaPlayer siren = MediaPlayer.create(this, R.raw.siren);
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Thread counter = new Thread(new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
try{
Thread.sleep(2000);
radar.setImageResource(R.drawable.radar_new_full);
Thread.sleep(3000);
radar.setImageResource(R.drawable.radar_new_50);
Thread.sleep(2000);
radar.setImageResource(R.drawable.radar_new_found);
} catch (InterruptedException e) …Run Code Online (Sandbox Code Playgroud)