playMaker

Author Topic: I need to conver this C# script to a playmaker action.  (Read 1471 times)

Silicon Power

  • Full Member
  • ***
  • Posts: 186
I need to conver this C# script to a playmaker action.
« on: August 13, 2020, 07:35:03 AM »
Hi. this C# script can get material index of an object where you click. Can someone please convert it to a playmaker action?
« Last Edit: August 14, 2020, 12:40:12 AM by Silicon Power »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: I need to conver this C# script to a playmaker action.
« Reply #1 on: August 13, 2020, 05:15:16 PM »
hi, i think you forgot to link the script :)

Silicon Power

  • Full Member
  • ***
  • Posts: 186
Re: I need to conver this C# script to a playmaker action.
« Reply #2 on: August 14, 2020, 12:39:20 AM »
hi, i think you forgot to link the script :)

Sorry yes I forgot to copy the C# code.

Code: [Select]
using UnityEngine;

public class FindHitSubMesh : MonoBehaviour
{

    private int[] subMeshesFaceTotals;
    private int totalSubMeshes;

    void Awake()
    {
        MeshFilter mf = (MeshFilter)gameObject.GetComponent(typeof(MeshFilter));
        Mesh mesh = mf.mesh;

        totalSubMeshes = mesh.subMeshCount;
        subMeshesFaceTotals = new int[totalSubMeshes];

        for (int i = 0; i < totalSubMeshes; i++)
        {
            subMeshesFaceTotals[i] = mesh.GetTriangles(i).Length / 3;
        }
    }


    void OnMouseDown()
    {

        RaycastHit hit;

        if (!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity))
            return;

        int hitSubMeshNumber = 0;
        int maxVal = 0;

        for (int i = 0; i < totalSubMeshes; i++)
        {
            maxVal += subMeshesFaceTotals[i];

            if (hit.triangleIndex <= maxVal - 1)
            {
                hitSubMeshNumber = i + 1;
                break;
            }

        }

        Debug.Log("We hit sub mesh number: " + hitSubMeshNumber);
    }
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: I need to conver this C# script to a playmaker action.
« Reply #3 on: August 24, 2020, 02:32:42 AM »
Hi,

 uhm, interesting, let me work on that, I'll get back to you when done.


Bye,

 Jean