Search Unity

  1. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice

Calling a javascript function from TypeScript file

Discussion in 'Project Tiny' started by Antumarin, Nov 17, 2020.

  1. Antumarin

    Antumarin

    Joined:
    May 21, 2017
    Posts:
    5
    As the title says, I'm trying to call a function coded in the html in js from inside a ts file in the project. I'm using Tiny 0.13.2. I know it's a very outdated version of Tiny but it's the one I've been told to use and honestly right now this is the only issue I can't seem to solve.
     
  2. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    588
    0.13.2 is not meant to be used anymore and is not compatible with newer versions at all, I doubt you will find any support for that version
     
  3. Antumarin

    Antumarin

    Joined:
    May 21, 2017
    Posts:
    5
    Not sure why you decided to reply just to give no answer but we still ended up finding the solution.

    Firstly, in the project's files (next to the Assets folder), you create a "External" folder, and inside you add the javascript file with whichever name you want (in my case I called it "cta.js") with the following code:
    Code (JavaScript):
    1. function callToAction () {
    2.   FbPlayableAd.onCTAClick();
    3. }
    Then you create a "tsconfig.override.json" file on the Tiny project with this code:
    Code (Json):
    1. {
    2.   "compilerOptions": {
    3.     "allowJs": true
    4.   },
    5.   "include": ["External/cta.js"]
    6. }
    And finally, inside your project's script, you just call the function "callToAction();".
     
unityunity