赞
踩
以下是几种写法:
1.
首先注意,新版unity中改变了2d中函数调用方式,新方式如下:
定义一个rb:
public Rigidbody2D rb;
在start函数中,
- void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- }
实际函数调用时:
rb.AddForce(x_addForce.x_force);
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class addForce : MonoBehaviour
- {
- public float x_power = 0.0f;
- public float y_power = 100.0f;
- public Rigidbody2D rb;
- Vector2 x_force ;
-
-
- public addForce()
- {
- x_force = new Vector2(x_power, y_power);
-
- }
-
- void Start()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。