unity 安卓陀螺仪脚本控制目标数量改写问题

一个可以让陀螺仪控制单个小球滚动的脚本
using System.Collections;

using System.Collections.Generic;
using UnityEngine;
yuan
public class Spaceship : MonoBehaviour {

Rigidbody2D rb;
float dirX;
float moveSpeed = 20f;

// Use this for initialization
void Start () {
    rb = GetComponent<Rigidbody2D> ();
}

// Update is called once per frame
void Update () {
    dirX = Input.acceleration.x * moveSpeed;
    transform.position = new Vector2 (Mathf.Clamp (transform.position.x, -7.5f, 7.5f), transform.position.y);
}

void FixedUpdate()
{
    rb.velocity = new Vector2 (dirX, 0f);
}

}

目前问题是以其为蓝本只修改了float moveSpeed 和 transform.position的“新”脚本,会和原脚本产生冲突

这个是视频原地址 https://y o u t u.be/wpSm2O2LIRM

img

我想要达到的结果是将该脚本改写部分,把修改后的脚本逐一复制到每个二维物体上(修改float moveSpeed 和 transform.position产生的不同脚本变体),来实现多个目标的异速移轴。

本人没有unity基础,请大家包涵,希望回答能附上代码,感激不尽。

应用到一个以上目标, 可以创建一个数组。