我一直在研究如何制造一个在平台上左右移动而不会脱落的敌人角色至少两个小时。我已经尝试了4个不同的脚本并经历了2个youtube教程,但我似乎只是在所有内容上都出现了错误。这是我的第一篇帖子,如果我做错了什么请通知我,谢谢你:)。
我的代码如下:
using UnityEngine;
using System.Collections;
public class EnemyPatrol : MonoBehaviour {
public float MoveSpeed;
public bool MoveRight;
public var velocity: Vector2;
void Update ()
{
if (MoveRight) {
public bool GetComponent<rigidbody2D>().velocity =
new Vector2(MoveSpeed, rigidbody2D.velocity.y);
} else {
public bool GetComponent<rigidbody2D>().velocity =
new Vector2(-MoveSpeed, rigidbody2D.velocity.y);
}
}
}
我的错误:
Assets/Scripts/EnemyPatrol.cs(8,28): error CS1519: Unexpected symbol \`:' in class, struct, or interface member declaration
Assets/Scripts/EnemyPatrol.cs(8,37): error CS1519: Unexpected symbol \`;' in class, struct, or interface member declaration
Assets/Scripts/EnemyPatrol.cs(13,30): error CS1525: Unexpected symbol \`public'
Assets/Scripts/EnemyPatrol.cs(15,30): error CS1525: Unexpected symbol \`public'
答案 0 :(得分:1)
这是一个非常简单的解决方案,可以帮助您入门。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include <sys/sysctl.h>
#include <sys/stat.h>
const char *getExecutablePath(char *epath) {
int mib[4];
char **argv;
size_t len;
const char *comm;
int ok = 0;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC_ARGS;
mib[2] = getpid();
mib[3] = KERN_PROC_ARGV;
if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0)
abort();
if (!(argv = malloc(len)))
abort();
if (sysctl(mib, 4, argv, &len, NULL, 0) < 0)
abort();
comm = argv[0];
if (*comm == '/' || *comm == '.') {
if (realpath(comm, epath))
ok = 1;
} else {
char *sp;
char *xpath = strdup(getenv("PATH"));
char *path = strtok_r(xpath, ":", &sp);
struct stat st;
if (!xpath)
abort();
while (path) {
snprintf(epath, PATH_MAX, "%s/%s", path, comm);
if (!stat(epath, &st) && (st.st_mode & S_IXUSR)) {
ok = 1;
break;
}
path = strtok_r(NULL, ":", &sp);
}
free(xpath);
}
if (ok)
*strrchr(epath, '/') = '\0';
free(argv);
return ok ? epath : NULL;
}
int main(void) {
char path[PATH_MAX];
if (getExecutablePath(path))
puts(path);
return 0;
}