spring joint 2d组件,是弹簧关节,相当于一个弹簧,属于物理组件的2d关节的弹簧关节
物体添加组件后相当于弹簧一边是这个物体,另一边是一个自己设定的地方
要弹射某东西,当物体距离弹簧一端距离够大时,用脚本控制spring joint的enabled值为false
小鸟代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bird : MonoBehaviour
{
bool shootcontrol=false;
public Transform centerpos;
public float maxdis = 2.0f;
SpringJoint2D apj;
Rigidbody2D rg;
public LineRenderer left, right;
public Transform right1, left1;
// Start is called before the first frame update
void Start()
{
rg = GetComponent<Rigidbody2D>();