我是编程的新手,这是Collision Physics&Rigidbody Movement的代码,但是当我保存脚本时,unity证明了这一点。问题在第45和50行。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour {
public float moveSpeed;
private Animator anim;
private Rigidbody2D myRigidbody;
private bool playerMoving;
private Vector2 lastMove;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
myRigidbody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
playerMoving = false;
if(Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
{
//transform.Translate (new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
myRigidbody.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * moveSpeed, myRigidbody.velocity.y);
playerMoving = true;
lastMove = new Vector2(Input.GetAxisRaw("Horizontal"), 0f );
}
if(Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f )
{
//transform.Translate (new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, Input.GetAxisRaw("Vertical") * moveSpeed);
playerMoving = true;
lastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
}
If(Input.GetAxisRaw("Horizontal") < 0.5f && Input.GetAxisRaw("Horizontal") > -0.5f)
{
myRigidbody.velocity = new Vector2(0f, myRigidbody.velocity.y);
}
If(Input.GetAxisRaw("Vertical") < 0.5f && Input.GetAxisRaw("Vertical") > -0.5f )
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, 0f);
}
anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
anim.SetFloat("MoveY", Input.GetAxisRaw("Vertical"));
anim.SetBool("PlayerMoving", playerMoving);
anim.SetFloat("LastMoveX", lastMove.x);
anim.SetFloat("LastMoveY", lastMove.y);
}
}
答案 0 :(得分:2)
这两个:
this
是方法调用,因为您写的是onDeleteClick(e,data) {
e.preventDefault();
this.dataToBeDeleted = data;
this.setState({
showDeleteDialog: true
});
}
<PivotItem linkText="My Scenarios" itemCount={this.state.scenarios.length} >
<div className="tab-content">
<div className="details-table">
<table>
<thead>
<tr>
<th>Name</th>
<th>Last Modified</th>
<th>Owner</th>
<th className="actions">Actions</th>
</tr>
</thead>
<tbody>
{
this.state.scenarios.map((scenariosItem, sIndex) => {
return (
<tr className="list-row" key={sIndex}>
<td className="item-name">
<div>
<div className="item-icon"><i className="bod-industry-icon icon-Scenarios"></i></div>
<div className="item-info">{scenariosItem.title}
</div>
</div>
</td>
<td className="author">{moment(scenariosItem.utcDate).startOf('minutes').fromNow()}</td>
<td className="activity">{scenariosItem.creator}</td>
<td className="actions">
<IconButton iconProps={{ iconName: 'Edit' }}
title=""
ariaLabel="Edit"
onClick={
() => {
let url = '/c/scenarios/' + scenariosItem.ElementId;
window.open(url, '_self');
}
}
/>
<IconButton iconProps={{ iconName: 'EdgeLogo' }}
title=""
ariaLabel="Preview"
onClick={
() => {
let url = '/c/scenarios/' + scenariosItem.ElementId + "?preview=true";
window.open(url, '_blank');
}
}
/>
<IconButton iconProps={{ iconName: 'Delete' }}
title=""
ariaLabel="Delete"
onClick={
(e) => this.onDeleteClick(e, scenariosItem)
}
/>
</td>
</tr>
);
})
}
</tbody>
</table>
</div>
{
this.state.scenarios.length > 0 ? <a className="pull-right" href="/c/search/?type=8&cat=1">View all records</a> : null
}
</div>
</PivotItem>
<PivotItem linkText="My Collections" itemCount={this.state.collections.length} >
<div className="tab-content">
<div className="details-table">
<table>
<thead>
<tr>
<th>Name</th>
<th>Last Modified</th>
<th>Owner</th>
<th className="actions">Actions</th>
</tr>
</thead>
<tbody>
{
this.state.collections.map(function (collectionsItem, colIndex) {
const collectionIcon = collectionsItem.IndustryIcon ? collectionsItem.IndustryIcon : 'bod-industry-icon icon-Industry';
return (
<tr className="list-row" key={colIndex}>
<td className="item-name">
<div>
<div className="item-icon"><i className={collectionIcon}></i></div>
<div className="item-info">{collectionsItem.title}</div>
</div>
</td>
<td className="activity">{moment(collectionsItem.utcDate).startOf('minutes').fromNow()}</td>
<td className="author">{collectionsItem.creator}</td>
<td className="actions">
<IconButton iconProps={{ iconName: 'Edit' }}
title=""
ariaLabel="Edit"
onClick={
() => {
let url = '/c/collections/' + collectionsItem.ElementId;
window.open(url, '_self');
}
}
/>
<IconButton iconProps={{ iconName: 'EdgeLogo' }}
title=""
ariaLabel="Preview"
onClick={
() => {
let url = '/c/collections/' + collectionsItem.ElementId + "?preview=true";
window.open(url, '_blank');
}
}
/>
<IconButton iconProps={{ iconName: 'Delete' }}
title=""
ariaLabel="Delete"
onClick={
(e) => this.onDeleteClick(e, collectionsItem)
}
/>
</td>
</tr>
);
})
}
</tbody>
</table>
</div>
{
this.state.collections.length > 0 ? <a className="pull-right" href="/c/search/?type=26&cat=1">View all records</a> : null
}
</div>
</PivotItem>
而不是If(Input.GetAxisRaw("Horizontal") < 0.5f && Input.GetAxisRaw("Horizontal") > -0.5f)
...
If(Input.GetAxisRaw("Vertical") < 0.5f && Input.GetAxisRaw("Vertical") > -0.5f )
。
C#编译器区分大小写,if语句的C#关键字为If
,而不是if
。
因此,编译器无法理解为什么您在方法调用后加上一个块而不是一个分号:
if
可以很容易地使它变得更清楚:
If
因此,将您的If(...) { ... }
语句更改为Console.WriteLine("Test") { ... }
,它应该会更好一些。