using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class speedup : MonoBehaviour
{
public Transform clothestank17;//建立物体clothestank17;
void OnTriggerEnter(Collider other)//碰撞后运行下方代码
{
Debug.Log("1");//运行到此处会输出“1”
if (other.tag == "Player")//如果tag=“Player”则运行下方代码
{
Debug.Log("2");//运行到此处会输出“2”
other.transform.parent = clothestank17;//变成clothestank17的子物体
other.transform.position = new Vector3(0, 0, 0);//移动到位置0,0,0
}
}
}
我操控tag=Player,name=clothestank17,碰撞到物体B。代码成功运行到了指定位置,从上图中1和2被读出就能知道。
但是在Unity中,我并未能看到物体B变成了clothestank17的子物体,并且clothestank17被传送到了世界空间的0,0,0位置。
我想要的效果是:当2被输出时,物体B会变成clothestank17(物体A)的子物体,并且物体B相对于父物体,也就是以父物体为原点,移动到0,0,0的位置。但我的代码貌似有错,希望能改正一下
哇哦,你是不是问过这个问题呀兄弟,看脚本好像是我上次给你解释的有问题,我私信给你写个demo