Home > Net >  I have a script which I have used on two objects and, Rigidbody2d.bodytype changes to static but is
I have a script which I have used on two objects and, Rigidbody2d.bodytype changes to static but is

Time:02-28

Here is my script code:

 using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ControlSpike : MonoBehaviour
{
    private static ControlSpike _instance = null;
    public static ControlSpike Instance { get { return _instance; } }
    public Rigidbody2D spikeBody;

    public void Awake()
    {
        _instance = null;
        if (_instance != null && _instance != this)
        {
          
            
        }
        else
        {
            _instance = this;
        }
        spikeBody.bodyType = RigidbodyType2D.Static;

    }

    // Start is called before the first frame update
    void Start()
    {
        spikeBody.bodyType = RigidbodyType2D.Static;
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    public void DropSpikes()
    {
        if (DrawingManager.Instance.paths.Contains(DrawingManager.Instance.clone) && VehicleSimpleControl._instance.RacePress)
        {
            spikeBody.bodyType = RigidbodyType2D.Dynamic;
            spikeBody.gravityScale = 10f;
        }
        
    }
}

The rigidbody.body type changes bodytype of one gameobject to dynamic but doesnt change the bodytype of the second gameobject to dynamic. Both get changed to static though. What could be wrong? Thanks in Advance!

CodePudding user response:

So, I created a manager for this in which I created two rigidbodies references. I passed the references of my objects in this manager and it worked. Basically, the code is same I just removed the script from the gameobjects and created a manager for them instead.

  • Related