C# 弹簧接头像绳子一样工作,不像弹簧
我想在我的游戏中使用弹簧关节2d。这里我有一些关于SpringJoint的代码,我正在尝试创建一个类似愤怒的小鸟的游戏。但在这里,我无法使弹簧接头2d工作。它像一根绳子一样工作,不像弹簧那样受力C# 弹簧接头像绳子一样工作,不像弹簧,c#,unity3d,C#,Unity3d,我想在我的游戏中使用弹簧关节2d。这里我有一些关于SpringJoint的代码,我正在尝试创建一个类似愤怒的小鸟的游戏。但在这里,我无法使弹簧接头2d工作。它像一根绳子一样工作,不像弹簧那样受力 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; public class Proj
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Projectile_dragging : MonoBehaviour {
public LineRenderer catapultLineFront;
public LineRenderer catapultLineBack;
private bool clickedOn;
void Start(){
LineRenderersetup ();
}
void Update(){
if(clickedOn)
Dragging();
LineRendererUpdate ();
}
void OnMouseDown(){
clickedOn = true;
}
void OnMouseUp(){
GetComponent<Rigidbody2D>().isKinematic = false;
clickedOn = false;
}
void LineRendererUpdate(){
//Vector2 hold = transform.position - catapultLineFront.transform.position;
Vector3 hold = transform.position;
//leftRay.direction = projectile;
//Vector3 hold = leftRay.GetPoint(projectile.magnitude + radius);
catapultLineFront.SetPosition(1, hold);
catapultLineBack.SetPosition(1, hold);
}
void LineRenderersetup(){
catapultLineBack.SetPosition (0, catapultLineBack.transform.position);
catapultLineFront.SetPosition (0, catapultLineFront.transform.position);
catapultLineBack.sortingLayerName = "Foreground";
catapultLineFront.sortingLayerName = "Foreground";
catapultLineBack.sortingOrder = 1;
catapultLineFront.sortingOrder = 3;
}
void Dragging(){
Vector3 mouseworldpoint = Camera.main.ScreenToWorldPoint (Input.mousePosition);
mouseworldpoint.z = 0f;
transform.position = mouseworldpoint;
}
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用UnityEngine.UI;
使用UnityEngine.EventSystems;
公共类:单行为{
公共线路;
公共直线加速器;
私人住宅点击;
void Start(){
linerendersetup();
}
无效更新(){
如果(单击打开)
拖动();
linerenderupdate();
}
void OnMouseDown(){
单击On=true;
}
void OnMouseUp(){
GetComponent().IsKinetic=false;
clickedOn=false;
}
void lineRenderUpdate(){
//Vector2保持=transform.position-弹射器线front.transform.position;
矢量3保持=变换位置;
//leftRay.direction=射弹;
//Vector3 hold=leftRay.GetPoint(射弹大小+半径);
弹射器直线前端。设置位置(1,保持);
弹射器直线后退。设置位置(1,保持);
}
void linerendersetup(){
catapultLineBack.SetPosition(0,catapultLineBack.transform.position);
catapulinefront.SetPosition(0,catapulinefront.transform.position);
catapultLineBack.sortingLayerName=“前景”;
catapultLineFront.sortingLayerName=“前景”;
catapultLineBack.sortingOrder=1;
弹射器线前部。排序顺序=3;
}
无效拖动(){
Vector3 mouseworldpoint=Camera.main.ScreenToWorldPoint(Input.mousePosition);
mouseworldpoint.z=0f;
transform.position=mouseworldpoint;
}
}
我只看到了
线条渲染器
,但是你是在哪里创建的弹簧关节2D
?哦,我是手动附加的。你能在附加的弹簧关节
中包含你的游戏对象
的图片,以及描述你的问题的视频吗?您需要指定弹簧的放置位置以及它应该推动什么。@Hristo我在这里附上了图片,请检查一下。